Jump to content

Recommended Posts

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>";
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/69588-php-mysql-guestbook-error/
Share on other sites

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;

 

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.