Jump to content

Recommended Posts

I have an app on my site and it currently displays 3 items in a 'news ticker' that rotates.... This is what I currently have..

 

<div id="NewsVertical">
     <ul id="TickerVertical">
<li>
      <h3><?php echo $title ?></h3>
   <span><p><?php echo $infobox ?></span>
</li>
<li>
   <h3><?php echo $title1 ?></h3>
   <span><?php echo $infobox1 ?></span>
</li>
<li>
   <h3><?php echo $title2 ?></h3>
   <span><?php echo $infobox2 ?></span>
</li>
      </ul>
    </div>
</div>

 

and it works great but this is what I'm trying to do to so I can take off the 3 limitation that I currently have...

 

<div id="NewsVertical">
     <ul id="TickerVertical">
<?php
$lines = file('http://localhost/modules/mod_game/info.dcc', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($lines as $n_line)
{
    list($title, $infobox) = explode('-', $n_line);
echo '<h3>'. $title .'</h3><br /><p>'.$infobox.;
}
?>

 

However now it just crashes and will not display anything.. What have I missed here?

 

Thank you in advance!!

 

John

Link to comment
https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/
Share on other sites

drop the last dot, its not needed and throws an error. Why dont you turn on error checking?

echo '<h3>'. $title .'</h3><br /><p>'.$infobox;

and why not use double quotes so you are a bit less confused.

echo "<h3>$title </h3><br /><p>$infobox";

 

 

HTH

Teamatomic

Awesome..Thank you!!  I did find the problem without that though.. my own stupid mistake LOL

 

I have open php tags in the beginning and the end... it looks like this:

 

<?php
If ($nticker=="0") {
  ?>
    <div id="NewsTicker">
    <div id="controller">
    <div id="stop_scroll_cont"><a id="stop_scroll"><img src="http://localhost/modules/mod_game/img/stop.png" width="14" height="14" border="0" align="absmiddle" /></a> Stop news scroll</div>
    <div id="play_scroll_cont"><a id="play_scroll"><img src="http://localhost/modules/mod_game/img/play.png" width="14" height="14" border="0" align="absmiddle"/></a> Play news scroll</div>
    </div>

<div id="NewsVertical">
     <ul id="TickerVertical">
<li><h3><? echo $title ?></h3>
<span><p><? echo $infobox ?></span></li>
      </ul>
    </div>
</div>


<script language="javascript" type="text/javascript" src="/modules/mod_game/js/newsticker.js"></script>
<?php
  }
?>

 

That was to escape the PHP to show HTML.. NOW the problem I have to figure out is how to stuff the following in there too to make it all work...

 

$lines = file('modules/mod_game/info.txt');
foreach($lines as $line);

list($title, $infobox) = explode('-', $line);

 

Any ideas where I can put that? 

This is what I have and so far the box shows up but it literally is showing "$Title" and "$infobox" in the box ... and not what's in the info.txt file... any ideas?

 

<?php
If ($nticker=="0") {
  ?>


    <div id="NewsTicker">
    <div id="controller">
    <div id="stop_scroll_cont"><a id="stop_scroll"><img src="modules/mod_game/img/stop.png" width="14" height="14" border="0" align="absmiddle" /></a> Stop news scroll</div>
    <div id="play_scroll_cont"><a id="play_scroll"><img src="modules/mod_game/img/play.png" width="14" height="14" border="0" align="absmiddle"/></a> Play news scroll</div>
    </div>

<div id="NewsVertical">
<ul id="TickerVertical">
<?
$lines = file('modules/mod_game/info.txt');
foreach($lines as $line);
list($title, $infobox) = explode('-', $line);
echo "<li><h3>" $title "</h3><span><p>" $infobox "</span></li>";

</ul></div></div>


<?php
  }
    include ('tmpl/in.php');
?>

Well I figured out the problem and it displays but doesn't rotate throw the info.txt file..LOL

 

THe problem was I had a php tag in the beginning...terminated it and one at the end terminated. I was trying to put one in the middle and that just threw errors..

 

like this..

 

<?php
If ($nticker=="0") {
  ?>


    <div id="NewsTicker">
    <div id="controller">
    <div id="stop_scroll_cont"><a id="stop_scroll"><img src="modules/mod_game/img/stop.png" width="14" height="14" border="0" align="absmiddle" /></a> Stop news scroll</div>
    <div id="play_scroll_cont"><a id="play_scroll"><img src="modules/mod_game/img/play.png" width="14" height="14" border="0" align="absmiddle"/></a> Play news scroll</div>
    </div>

<div id="NewsVertical">
<ul id="TickerVertical">
<?php
$lines = file('info.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($lines as $line);
list($title, $infobox) = explode('-', $line);
echo '<li><h3>'.$title.'</h3><span><p>'.$infobox.'</span></li>';
?>
</ul></div></div>


<?php
  }
    include ('tmpl/in.php');
?>

 

If I take out the php tag and the ?> from the echo $title and $infobox section it doesn't error but it just shows the $title and $infobox as text, not a variable.

 

I did do this...

 

<?php
If ($nticker=="0") {  
   $lines = file('modules/mod_game/info.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($lines as $line);
list($title, $infobox) = explode('-', $line);
    echo '<div id="NewsTicker">';
    echo '<div id="controller">';
echo '<div id="stop_scroll_cont"><a id="stop_scroll"><img src="modules/mod_game/img/stop.png" width="14" height="14" border="0" align="absmiddle" /></a> Stop news scroll</div>';
    echo '<div id="play_scroll_cont"><a id="play_scroll"><img src="modules/mod_game/img/play.png" width="14" height="14" border="0" align="absmiddle"/></a> Play news scroll</div>';
    echo '</div>';

echo '<div id="NewsVertical">';
echo '<ul id="TickerVertical">';


echo '<li><h3>'.$title.'</h3><span><p>'.$infobox.'</span></li>';

echo '</ul></div></div>';

}
    include ('tmpl/in.php');
echo '<script language="javascript" type="text/javascript" src="/modules/mod_game/js/newsticker.js"></script>';
?>

 

and now it shows the text from the file but only 1 line... so if I have mulitple lines it only shows the last line...

If I can figure that out I'd be gold...  I am probably making this way harder than it has to be but I've been looking at this for 4 days and my mind is probably confused and scrambled... LOL

You have closed your foreach before it's done anything.  treat it like a while loop. 

foreach($lines as $line) { //you had a ; at the end here
list($title, $infobox) = explode('-', $line);
echo '<li><h3>'.$title.'</h3><span><p>'.$infobox.'</span></li>';
} //close the loop
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.