Hi Guys,
i thoguht this part was gonna be a breeze but something isn't right, i have 4 entries in a test database i put the max results per page to 1 as a test for th epagination the links are correct they show:
<<< 1 2 3 4 >>>
BUT they show all 4 per page rather than just 1
can anyone see what i have done wrong:
cheersPHP Code:## echo table #####################################################################
echo '<br />
<table width="500" border="1" bordercolor="#000000" cellpadding="3" cellspacing="0" />
<form action="'.$_SERVER['PHP_SELF'].'" method="POST" />
<tr>
<td bgcolor="#004E98" colspan="2"><img src="images/guestbook.gif" /></td>
</tr>
<tr>
<td align="right">Please Enter Your Name:</td><td align="left"><input type="text" name="name" size="30" /></td>
</tr>
<tr>
<td align="right">Please Enter Your E-Mail:</td><td align="left"><input type="text" name="email" size="30" /></td>
</tr>
<tr>
<td align="right">Please Enter Location:</td><td align="left"><input type="text" name="from" size="30" /></td>
</tr>
<tr>
<td align="right">Your Message To Eileen:</td><td align="left"><textarea name="message" cols="30" rows="10"></textarea></td>
</tr>
<tr>
<td bgcolor="#004E98" colspan="2" align="right" /><input class="btn" type="submit" name="submit_entry" value="Add Guestbook Entry >>>" onclick="return confirm(\'Are You Sure All Fields Are Filled In?\');"></td>
</tr>
</table></form>';
## loop out the entries #####################################################
## Pagination start #############################################################
echo "<center>";
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 1;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM `guestbook` LIMIT $from, $max_results");
## Pagination start #############################################################
## query results then loop ##################################################
$query_gb = "SELECT * FROM `guestbook` ORDER BY `date` DESC";
$result_gb = mysql_query($query_gb) or die (mysql_error());
## the loop #################################################################
while($row = mysql_fetch_array($result_gb)) {
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$from = $row['from'];
$message = $row['message'];
echo "<table width=\"500\" border=\"1\" bordercolor=\"#000000\" cellpadding=\"5\" cellspacing=\"0\" />
<tr>
<td bgcolor=\"#5CB3FF\" colspan=\"2\" align=\"left\"><b>Entry Number:</b> $id</td></tr><tr><td colspan=\"2\" align=\"left\"><b>Name:</b> <font color=\"red\"><b>$name</b></font></td></tr><tr><td colspan=\"2\" align=\"left\"><b>From:</b> $from</td><tr><td colspan=\"2\" align=\"left\"><b>E-Mail Address:</b> $email</td></tr><tr><td align=\"left\" colspan=\"2\" bgcolor=\"#ffffff\">$message</td></tr>";
echo '</table><br />';
}
## Pagination end ###############################################################
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `guestbook`"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo " <a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><font color=\"#000000\"><<< </font></a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "[<b>$i</b>] ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\"><font color=\"#000000\">$i</font></a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"><font color=\"#000000\"> >>></font></a>";
}
echo "<br /><br />";
## Pagination end ###############################################################
}
Graham








Bookmarks