tbare Posted January 4, 2008 Share Posted January 4, 2008 <?php //read data from the news file in /text_files/index.txt and prints it a line at a time $text = file('text_files/index.txt'); $spacer = '`~`'; //define the breaking point for explode() function $count = 1; $toShow = 5; if(isset($_GET['show'])){ $show= $_GET['show']; } foreach ($text as $line) { if(!isset($show) && $count <= $toShow){ list ($date, $content) = explode($spacer, $line); //seperates line into to date, content and name data $content = stripslashes($content); //strips slashes in front of quote marks for content print "<tr><td valign='top' align='center'>"; print "<font color=#000000><strong>$date</strong></font>"; //prints date print "<td align='right'>$content"; //prints content print "</td>"; print "</tr>"; $count++; } elseif(isset($show) && $show="all"){ list ($date, $content) = explode($spacer, $line); //seperates line into to date, content and name data $content = stripslashes($content); //strips slashes in front of quote marks for content print "<tr><td valign='top' align='center'>"; print "<font color=#000000><strong>$date</strong></font>"; //prints date print "<td align='right'>$content"; //prints content print "</td>"; print "</tr>"; } } if(!isset($show)){ print "<tr><td colspan=2><center><a href='index.php?show=all'>show all updates</a></center></td></tr>"; } ?> It works, but it's allowing any value for $show to show all... (so i could type in "index.php?show=asdfasdfasfdasf" and it would show all of the news... this isn't a HUGE deal, i'm just stumped as to why it's not working how i have it... Link to comment https://forums.phpfreaks.com/topic/84520-solved-why-doesnt-this-work-properly/ Share on other sites More sharing options...
awpti Posted January 4, 2008 Share Posted January 4, 2008 elseif(isset($show) && $show="all"){ Change to.. elseif(isset($show) && $show === "all"){ Link to comment https://forums.phpfreaks.com/topic/84520-solved-why-doesnt-this-work-properly/#findComment-430606 Share on other sites More sharing options...
tbare Posted January 4, 2008 Author Share Posted January 4, 2008 thanks.... i made the change here though: if(isset($_GET['show'])){ $show= $_GET['show']; } to if(isset($_GET['show']) && $show==="all"){ $show= $_GET['show']; } otherwise if something else was entered, i got a blank screen instead of showing the 5 line... SOLVED! thanks again Link to comment https://forums.phpfreaks.com/topic/84520-solved-why-doesnt-this-work-properly/#findComment-430607 Share on other sites More sharing options...
tbare Posted January 4, 2008 Author Share Posted January 4, 2008 i lied... not solved... your method DID work, just again, w/ the blank white screen if something other than "all" was defined... i'm going to try something else here... will post when done Link to comment https://forums.phpfreaks.com/topic/84520-solved-why-doesnt-this-work-properly/#findComment-430609 Share on other sites More sharing options...
tbare Posted January 4, 2008 Author Share Posted January 4, 2008 ok new code: <? if(isset($_GET['show'])){ $show= $_GET['show']; } foreach ($text as $line) { if((!isset($show) && $count <= $toShow) || $show !== "all"){ list ($date, $content) = explode($spacer, $line); //seperates line into to date, content and name data $content = stripslashes($content); //strips slashes in front of quote marks for content print "<tr><td valign='top' align='center'>"; print "<font color=#000000><strong>$date</strong></font>"; //prints date print "<td align='right'>$content"; //prints content print "</td>"; print "</tr>"; $count++; } elseif(isset($show) && $show==="all"){ list ($date, $content) = explode($spacer, $line); //seperates line into to date, content and name data $content = stripslashes($content); //strips slashes in front of quote marks for content print "<tr><td valign='top' align='center'>"; print "<font color=#000000><strong>$date</strong></font>"; //prints date print "<td align='right'>$content"; //prints content print "</td>"; print "</tr>"; } } if(!isset($show) || $show !== "all"){ print "<tr><td colspan=2><center><a href='?show=all'>show all updates</a></center></td></tr>"; } ?> this works: if(!isset($show) || $show !== "all"){ print "<tr><td colspan=2><center><a href='?show=all'>show all updates</a></center></td></tr>"; } this doesn't: if((!isset($show) && $count <= $toShow) || $show !== "all"){ (ie, if '?show=foobar' i'll get the "show all updates" link @ the bottom of the page, but all of the content will be there, too... if '?show=all' the "show all updates" link isn't there, and all content is there... if '?show=' isn't in the URL at all, all content from the file and the "show all updates" is there ) anyone know why? (sorry for my OCD... it's a sickness...) :-/ Link to comment https://forums.phpfreaks.com/topic/84520-solved-why-doesnt-this-work-properly/#findComment-430617 Share on other sites More sharing options...
tbare Posted January 4, 2008 Author Share Posted January 4, 2008 ok.. solved again... (i'm an idiot, don't say anything)... if((!isset($show) || $show !=="all") && $count <= $toShow){ Link to comment https://forums.phpfreaks.com/topic/84520-solved-why-doesnt-this-work-properly/#findComment-430633 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.