Pagination not working
Posted: Fri Nov 07, 2003 1:35 am
Check out this page. http://theultimategiftbasket.com/ca...at=gift_baskets
I am try to make it so there are 5 pages on each page, no matter how many products there are, and to have it have next and previous links, IF there are next and previous pages, but not if there isn't. Right now I only have 15 products, so the code is just set for that, but I would like it to find the last returned row and base the amount of pages off that. I have seen very complicated ways of doing pagination, and I am a php newb and did not understand it. Page 1 works fine, but page 2 won't go to page 3, it just reloads page 2 again (products 6-10). Here is my code. Please tell me why it's not totally working.
?>
I am try to make it so there are 5 pages on each page, no matter how many products there are, and to have it have next and previous links, IF there are next and previous pages, but not if there isn't. Right now I only have 15 products, so the code is just set for that, but I would like it to find the last returned row and base the amount of pages off that. I have seen very complicated ways of doing pagination, and I am a php newb and did not understand it. Page 1 works fine, but page 2 won't go to page 3, it just reloads page 2 again (products 6-10). Here is my code. Please tell me why it's not totally working.
Code: Select all
<?php
include("header.inc");
$limit=5;
if (!isset($offset)) {
$offset=0;
}
$result = @mysql_query("SELECT * FROM gifts WHERE category ='$cat' limit $offset, $limit");
echo("<table width="100%" border="0" cellpadding="0" cellspacing="0">");
while($data = mysql_fetch_array($result)) {
echo("
<tr>
<td colspan="2">
<font size="2">
<a href="product.php?product_id=$dataCode: Select all
"><img src="images/products/th_$dataCode: Select all
.jpg" align="left" /></a><b>$data[name]</b> (No. $dataCode: Select all
)
<br />
<b>Price: $$data[price].00</b>
</font>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
");
}
echo("
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td width="50%" align="center">
");
if (!$offset == "0") {
echo("<a href="category.php?cat=gift_baskets&offset=".($offset = $offset - 5)."">Previous</a>");
}
echo("
</td>
<td width="50%" align="center">
");
if (!isset($data)) {
echo("<a href="category.php?cat=gift_baskets&offset=".($offset = $offset + 5)."">Next</a>");
}
echo("
</td>
</tr>
</table>
");
include("footer.inc");
?>