nav buttons not working correctly

From: Date: Tue, 14 Aug 2001 15:37:54 +0000
Subject: nav buttons not working correctly
Groups: php.general 
Request: Send a blank email to php-general+get-62662@lists.php.net to get a copy of this message
I have some existing code that I want to modify to limit the display results to 5 rows and add nav buttons to display the next set of 5, etc. You all know what I am looking for. I have a book- MySQL/PHP Database Applications by Greenspan & Bulger - which has an example that should work, but isn't. I have inserted the function from the book and can get 5 rows on the first page, and the next button, but the second page doesn't display any rows. Pasted below is the code for my page, the function in question is down aways. I am just learning this stuff, so don't be too hard on me about the existin code, it works fine with- out the nav function. I am sure there are probably more efficient ways to write this, but for now I just want to get the nav function to work properly. (some lines will undoubtedly wrap and make it all look real ugly) ----------------------------------------------------------------- <? $conn = @mysql_connect("localhost","root") or die ("could not connect to the server"); mysql_select_db("bulletins", $conn) or die ("could not get the database"); function authenticate ($realm="Secure Area",$errmsg="Please enter a usename and password") { header("WWW-Authenticate: Basic realm=\"$realm\""); header("HTTP/1.0 401 Unauthorized"); die($errmsg); } if (empty($PHP_AUTH_USER)) { authenticate($realm,$errmsg,"header"); } else { $query = "select name from users where password = ('$PHP_AUTH_PW') and name = ('$PHP_AUTH_USER')"; $result = mysql_query($query); if ($result) { list($valid_user) = mysql_fetch_row($result); } if (!$result || empty($valid_user)) { authenticate($realm,$errmsg,"query"); } } ?> <html> <head> <meta name="generator" content="HTML Tidy, see www.w3.org" /> <title>Dealer Bulletins, Simrad, Inc</title> <style type="text/css"> body { background-color: #b5e4f9; } </style> </head> <body> <center><h1>Simrad Dealer Bulletins</h1></center> <br /> <p>You can sort the bulletins in the following order:<br /> <font size="-1">(This will display all bulletins in one long page.)<br /> OR click on the bulletin subject line below (much quicker)</font> </p> <ul> <li> <a href="bulletin_sorter.php?orderby=date">Bulletin Date</a> (oldest to newest) </li> <li> <a href="bulletin_sorter.php?orderby=date2">Bulletin Date</a> (newest to oldest) </li> <li> Select bulletins from <a href="bulletin_sorter.php?orderby=vlad">Brian Vlad</a> - Plotter and Radar Products </li> <li> Select bulletins from <a href="bulletin_sorter.php?orderby=burke">Tom Burke</a> - Autopilots and Instrumentation </li> <li> Select bulletins from <a href="bulletin_sorter.php?orderby=hillers">Mike Hillers</a> - Fisheries </li> </ul> <br /> OR <br /> <form name="form1" action="bulletin_sorter.php" method="post"> Enter a word to search for: <input type="text" size="30" name="search"><br /> <input type="submit" name="submit" value="Search"> <font size="-1">(You must press the search button to complete the search)</font> </form> <br /> <? $result1 = mysql_query("select count(*) from dbulletins") or die(mysql_error()); echo "There are " .mysql_result($result1,0,0). " Bulletins listed in the database"; ?> <br /><br /> <hr width="75%" noshade="noshade" /> <table summary="" border="0" cellpadding="5" align="center" width="90%"> <? $db = mysql_connect("localhost", "root"); mysql_select_db("bulletins", $db); if ($orderby == 'date'): $sql = "select * from dbulletins order by 'bulletin_date'"; elseif ($orderby == 'date2'): $sql = "select * from dbulletins order by 'bulletin_date' desc"; elseif ($orderby == 'vlad'): $sql = "select * from dbulletins where bulletin_from1 like '%Vlad%' order by 'bulletin_number' desc"; elseif ($orderby == 'burke'): $sql = "select * from dbulletins where bulletin_from1 like '%Burke%' order by 'bulletin_number' desc"; elseif ($orderby == 'hillers'): $sql = "select * from dbulletins where bulletin_from1 like '%Hillers%' order by 'bulletin_number' desc"; elseif (isset($submit)): $sql = "select * from dbulletins where match (body) against ('%$search%')"; else: $sql = "select * from dbulletins order by 'bulletin_date' desc"; endif; $result2 = mysql_query($sql); while ( $row = mysql_fetch_array($result2)) { if ($orderby == 'vlad' || $orderby == 'burke' || $orderby == 'hillers' || $orderby =='date' || $orderby == 'date2' || $search == 'orderby'): { print("<tr>\n<td colspan=\"2\">\n<img src=\"1pixb5e4f9.gif\" alt=\"\" height=\"20\" width=\"1\">\n</td>\n</tr>"); print("<tr>\n<td bgcolor=\"white\" colspan=\"2\">\n<strong>\n"); printf("<font color=\"blue\">%s</font>\n</strong>\n</td>\n</tr>\n", $row["bulletin_number"]); print("<tr>\n<td valign=\"top\">\n<h2 class=\"c1\">\n<br />Dealer Bulletin</h2>"); printf("<strong>Date:</strong> %s\n", $row["bulletin_date"]); printf("<br />\n<strong>Number:</strong> %s\n", $row["bulletin_number"]); printf("<br />\n<strong>Subject:</strong> %s\n", $row["bulletin_subject"]); printf("<br />\n<strong>From:</strong> %s<br />%s\n", $row["bulletin_from1"], $row["bulletin_from2"]); print("</td>\n<td valign=\"top\" align=\"left\">\n"); print("<font face=\"Arial Black\" size=\"+6\">SIMRAD</font>\n"); print("<br />\n<font size=\"3\">&nbsp;&nbsp;&nbsp;A <strong>KONGSBERG</strong> Company</font>\n</center>\n"); print("<br />Simrad Inc.\n"); print("<br />19210-33<sup>rd</sup> Avenue West, Suite A\n"); print("<br />Lynnwood, WA 98036\n"); print("<br />U.S.A.\n"); print("<br />Telephone: 1-425-778-8821\n"); print("<br />Telefax: 1-425-771-7211\n"); print("<br />\n<br />\n</td>\n</tr>"); printf("<tr>\n<td colspan=2>%s\n", $row["body"]); print("<br />\n<hr width=\"75%\" />\n"); } else: printf("<tr><td>* <a href='bulletin_out.php?news_id=$row[news_id]'>%s</a>&nbsp;&nbsp;&nbsp;%s<br />&nbsp;&nbsp;&nbsp;%s</td></tr>", $row ["bulletin_subject"], $row["bulletin_date"], $row["bulletin_from1"]); endif; } function nav($offset=0,$this_script="bulletin_sorter.php") { global $php_self; $page_limit = 5; if (empty($this_script)) { $this_script = $php_self; } if (empty($offset)) { $offset = 0; } $result3 = mysql_query("select count(*) from dbulletins"); list($total_rows) = mysql_fetch_array($result3); print "<p>\n"; if ($offset > 0 ) { print "<a href=\"$this_script?offset=".($offset-page_limit)."\">&lt;&lt;Previous</a> &nbsp; "; } if ($offset+page_limit < $total_rows) { print "<a href=\"$this_script?offset=".($offset+page_limit)."\">Next&gt;&gt;</a> &nbsp; "; } print "</p>\n"; } ?> </table> <? nav(); ?> </body> </html> ---------------------------------------------------------------------- Thanks for any help you all can provide, Chip Wiegand Computer Services www.simradusa.com chip.wiegand@simrad.com Simrad, Inc Lynnwood, WA 425-712-1138 "There is no reason anyone would want a computer in their home." --Ken Olson, president, chairman and founder of Digital Equipment Corp., 1977 (-- Then why do I have nine? Somebody help me!)

« previous php.general (#62662) next »