cowboysdude Posted May 12, 2010 Share Posted May 12, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/ Share on other sites More sharing options...
teamatomic Posted May 12, 2010 Share Posted May 12, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1056946 Share on other sites More sharing options...
cowboysdude Posted May 12, 2010 Author Share Posted May 12, 2010 Nice catch! But it didn't work.. error checking? Well I'd love to but it's a test server [local] and I have checked the Apache error logs as well as the php and nothing shows.... Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1057208 Share on other sites More sharing options...
Muddy_Funster Posted May 12, 2010 Share Posted May 12, 2010 start your page with: <?php error_reporting (E_ALL); //your code here ?> That should then have the page display the error message rather than just being blank. Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1057218 Share on other sites More sharing options...
cowboysdude Posted May 12, 2010 Author Share Posted May 12, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1057233 Share on other sites More sharing options...
cowboysdude Posted May 13, 2010 Author Share Posted May 13, 2010 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1057475 Share on other sites More sharing options...
JasonO Posted May 13, 2010 Share Posted May 13, 2010 Between the variables and the string in your echo statement you do need the dots. Example: echo "<li><h3>".$title."</h3><span><p>".$infobox."</span></li>"; They are used to join your various pieces to form your line of code. Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1057477 Share on other sites More sharing options...
cowboysdude Posted May 13, 2010 Author Share Posted May 13, 2010 Thank you! I have tried that and instead of showing "$infobox" it just shows ".$infobox." LOL Not really sure why it's not working I am using the exact same lines in another program and it's working fine... Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1057500 Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 Try it like this: <?php echo "<li><h3>$title</h3><span><p>$infobox</span></li>"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1057504 Share on other sites More sharing options...
cowboysdude Posted May 13, 2010 Author Share Posted May 13, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1057516 Share on other sites More sharing options...
Muddy_Funster Posted May 13, 2010 Share Posted May 13, 2010 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/201447-what-im-trying-to-do-here/#findComment-1057601 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.