Hello everyone,
I have a table that i want to limit to 10 results per page and have a simple pagination script to generate the next 10 results. I have tried many different options, but alas it does not work. here is what I have so far.
<tbody>
<?
//specify how many results to display per page
$limit = 10;
//get pagination
$s = mysql_real_escape_string($_REQUEST['s']);
$results = mysql_query("SELECT * FROM products ORDER BY id LIMIT $s,$limit");
$row_num_links_main =mysql_num_rows ($results);
$n=0;
while($row = mysql_fetch_array($results)){
?>
<tr>
<td><? echo $n=$n+1 ?></td>
<td><? echo $row['itemnumber']?></td>
<td><a href="?editproduct=<? echo $row['id'] ?>"><? echo $row['productname'] ?></a></td>
<td>$<? echo $row['price'] ?></td>
<td><? $taxable = $row['taxable'];
if($taxable == 1){
$taxable = 'Yes';
}else{
$taxable = '';
} echo $taxable ?></td>
<td><a id="commentDelete" onClick="return delTicket(this.id);" href="?del=<? echo $row['id'] ?>">Delete</a></td>
</tr>
<? } ?>
</tbody>
<?
if($row_num_links_main > $limit){
// next we need to do the links to other search result pages
if ($s >=1) { // do not display previous link if 's' is '0'
$prevs=($s-$limit);
echo '<div class="search_previous"><a href="'.$PHP_SELF.'?s='.$prevs.'&q='.$var.'">Previous</a>
</div>';
}
// check to see if last page
$slimit =$s+$limit;
if (!($slimit >= $row_num_links_main) && $row_num_links_main!=1) {
// not last page so display next link
$n=$s+$limit;
echo '<div class="search_next"><a href="'.$PHP_SELF.'?s='.$n.'&q='.$var.'">Next</a>
</div>';
}
}
?>
Any ideas on how to get this to work?