joso Posted September 16, 2007 Share Posted September 16, 2007 hi, i seem to be getting an error on my guestbook script which ive attached below. the link to the book is: http://www.unearth-online.net/home.php?p=guestbook the idea was to have five entries per page, as you can see i've got an error showing and as you scroll through the pages it seems to just add 5 each time rather than show a different 5. hope someone can help! thanks <?php include "gb-database.php"; mysql_select_db($db, $connect); if (!isset($_GET['pagenum'])) { $pagenum = 1; } else { $pagenum = $_GET['pagenum']; } $data = mysql_query("SELECT * FROM comments order by id desc ") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 5; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit '.$page_rows.','.($pagenum-1) * $page_rows; $data_p = mysql_query("SELECT * FROM comments $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { Print $info['comments']; } if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?p=guestbook&pagenum=1'><strong><<<</strong> </a> |"; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?p=guestbook&pagenum=$previous'> <<<</a> "; } echo "| Page $pagenum of $last |"; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?p=guestbook&pagenum=$next'>>>></a> | "; echo " <a href='{$_SERVER['PHP_SELF']}?p=guestbook&pagenum=$last'><strong>>>></strong></a>"; } echo "<br /><br />"; mysql_data_seek($data_p, 0); while ($row = mysql_fetch_array($data_p)) { echo "<table width=\"400\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"left\" valign=\"top\">"; echo "<img src=\"images/layout/gb-border.jpg\" width=\"400\" height=\"5\" /></td></tr>"; echo "<tr><td align=\"left\" valign=\"top\"><table width=\"400\" border=\"0\" cellspacing=\"10\" cellpadding=\"0\"><tr>"; echo "<td colspan=\"2\" align=\"left\" valign=\"top\">" . $row['message'] . "</td>"; echo "</tr><tr>"; echo "<td width=\"110\" align=\"left\" valign=\"top\">Site Rating : " . $row['rating'] . "/10 </td>"; echo "<td width=\"260\" align=\"right\" valign=\"top\">Posted on " . $row['date'] . " by <a href=\"mailto:" . $row['email'] . "\">" . $row['name'] . "</a></td>"; echo "</tr></table></td></tr></table>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69588-php-mysql-guestbook-error/ Share on other sites More sharing options...
GingerRobot Posted September 16, 2007 Share Posted September 16, 2007 The reason why you simply get more records showing on each page is because you're not using the LIMIT clause in your mysql statement correctly. You have the parameters the wrong way round. Try changing this line: $max = 'limit '.$page_rows.','.($pagenum-1) * $page_rows; To: $max = 'limit '.($pagenum-1) * $page_rows.','.$page_rows; Quote Link to comment https://forums.phpfreaks.com/topic/69588-php-mysql-guestbook-error/#findComment-349740 Share on other sites More sharing options...
joso Posted September 18, 2007 Author Share Posted September 18, 2007 thanks for that man, I missed that. it works like a charm now Quote Link to comment https://forums.phpfreaks.com/topic/69588-php-mysql-guestbook-error/#findComment-350381 Share on other sites More sharing options...
AV1611 Posted September 18, 2007 Share Posted September 18, 2007 I'm in FF and don't see any errors on your page ??? Quote Link to comment https://forums.phpfreaks.com/topic/69588-php-mysql-guestbook-error/#findComment-350386 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.