WilliamMute
Programmer
- Jan 4, 2006
- 117
Hi all,
Thanks for viewing this post.
I have a dilema. I have used a piece of code which perfectly worked a a previous coursework I did, now its not working on this one am working on even though, I literally copied a past the code.
The am is to number the returned query result, i.e only display 5 results per page and the display next page numbers.
THEN MY While Statement. and then...
It does display the first 5 products and tells me the accurate amount of products that matches the search criterias, but when I click on the next 5 products, no results are returned.
Thanks for viewing this post.
I have a dilema. I have used a piece of code which perfectly worked a a previous coursework I did, now its not working on this one am working on even though, I literally copied a past the code.
The am is to number the returned query result, i.e only display 5 results per page and the display next page numbers.
Code:
<?php
$var = $_GET[id];
mysql_select_db($database_Connection, $Connection);
$table = "products";
$maxperpage = 5;
$sql = "Select count(*) as cnt from $table WHERE Category='$var'";
//query
$results = mysql_query($sql);
//how many rows
$row = mysql_fetch_assoc($results);
$numrows = $row['cnt'];
//pages we going to use
$numpages = ceil($numrows/$maxperpage);
//start
$offset = isset($_GET['offset'])?$_GET['offset']:0;
//query
$sql = "Select * from $table where Category ='$var' order by product_name limit $maxperpage offset $offset";
$results = mysql_query($sql);
?>
THEN MY While Statement. and then...
Code:
<? if ($numpages > 1): ?>
<div class="pages">
<?
for ($i=0; $i<$numpages; $i++):
$class = (($offset/$maxperpage) === $i) ? "current":"noncurrent";
?>
<a class="<?=$class?>" href="<?=$_SERVER['PHP_SELF']?>?id=<?php echo $var;?>?offset=<?=$i*$maxperpage?>"> <?=$i+1?></a>
<?
endfor;
?>
</div>
<? endif; ?>
It does display the first 5 products and tells me the accurate amount of products that matches the search criterias, but when I click on the next 5 products, no results are returned.