Jump to content

[SOLVED] why doesn't this work properly?


tbare

Recommended Posts

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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.