Re: Attempt At Prev/Next Links

From: Date: Sun, 19 Aug 2001 03:01:02 +0000
Subject: Re: Attempt At Prev/Next Links
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-63342@lists.php.net to get a copy of this message
> $max_row = 5; > if ($op == "next") { > $low = $low + $max_row; > $high = $low + $max_row; Either this... > $result = mysql_query("SELECT * FROM TABLENAME where Post='yes' LIMIT $low, $high"); > while($row = mysql_fetch_row($result)) { > echo "<b>$row[1] writes</b>:<br>\n"; > echo "&nbsp &nbsp <i>$row[2]</i><br>\n"; > echo "<b>AskLee writes</b>:<br>\n"; > echo "&nbsp &nbsp <i>$row[3]</i><br>\n"; > echo "<hr>\n"; > } > } > elseif ($op == "prev") { > $low = $low - $max_row; > $high = $high - $max_row; Or this is wrong. :-) I think $high should *always* be $low + $max_row; > $result = mysql_query("SELECT * FROM TABLENAME where Post='yes' LIMIT $low, $high"); > while($row = mysql_fetch_row($result)) { > echo "<b>$row[1] writes</b>:<br>\n"; > echo "&nbsp &nbsp > <i>$row[2]</i><br>\n"; > echo "<b>AskLee writes</b>:<br>\n"; > echo "&nbsp &nbsp > <i>$row[3]</i><br>\n"; > echo "<hr>\n"; > } > } else { Also, you really should compute your low/high, and *THEN* do one query, and one output. As it stands now, if you change your query/output, you have to change it in three places at once. > $low = 0; > $high = $low + $max_row; > $result = mysql_query("SELECT * FROM TABLENAME where Post='yes' LIMIT $low, $high"); > while($row = mysql_fetch_row($result)) { > echo "<b>$row[1] writes</b>:<br>\n"; > echo "&nbsp &nbsp <i>$row[2]</i><br>\n"; > echo "<b>AskLee writes</b>:<br>\n"; > echo "&nbsp &nbsp <i>$row[3]</i><br>\n"; > echo "<hr>\n"; > } > } > $result = mysql_query("SELECT * FROM mpn_asklee where Post='yes'"); > $num_rows = mysql_num_rows($result); > if ($num_rows > $max_row) { > echo "<table width=\"100%\" cellspacing=\"0\" > border=\"0\" cellpadding=\"0\">\n"; > echo "<tr><td align =\"left\">\n"; > if ($low > $max_row) { > echo "<a > href=\"$PHP_SELF?op=prev&low=$low&high=$high\">Previous</a>"; > } > echo "</td><td align =\"right\">\n"; > if ($num_rows > $high) { > echo "<a > href=\"$PHP_SELF?op=next&low=$low&high=$high\">Next</a>"; > echo "</td></tr></table>\n" > } > } > ?> Oh yeah: Start indenting between { and } The hair you save may be your own. -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#63342) next »