Hi,
I have been tryin to build this guestbook with dynamic previous and next links. I am tryin to print out 5 comments per page, it works for the first page, but after that it doesn't show anymore results. Can anyone please let me know wat I am suppose to do. I am really not gettin hold of this, I guess no sleep for while is gettin to me finally.
<?php
if (!isset($start))
{
$start = 0;
$db = mysql_connect ("localhost", "foo", "foo") ;
if (!$db)
{
echo "Cannot connect to the database at this moment, please try later again.";
}
mysql_select_db ("guestbook");
$retrieve = "SELECT * FROM guestbook LIMIT 0, 5";
$result = mysql_query ($retrieve);
$rows = mysql_num_rows ($result);
$pages = ceil ($rows / 5);
for ($i = 0; $i < $rows; $i++)
{
$fetch = mysql_fetch_array($result);
echo "<table width=200 border=1>";
echo "<tr>";
echo "<td>Name</td>";
echo "<td>".htmlspecialchars(stripslashes($fetch["name"]))."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Email</td>";
echo "<td>".htmlspecialchars(stripslashes($fetch["email"]))."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>City</td>";
echo "<td>".htmlspecialchars(stripslashes($fetch["city"]))."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Referred</td>";
echo "<td>".htmlspecialchars(stripslashes($fetch["referred"]))."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Comments</td>";
echo "<td>".htmlspecialchars(stripslashes($fetch["comments"]))."</td>";
echo "</tr>";
echo "<p><hr></p>";
echo "</table>";
}
if ($start > 0)
{
echo "<a href=\"".$PHP_SELF."?start=".($start - 1)."\">Previous</a><br>";
}
if ($start < $pages)
{
echo "<a href=\"".$PHP_SELF."?start=".($start + 1)."\">Next</a><br>";
}
}
?>