Wednesday, 28 August 2013

Pagination having issues with page id

Pagination having issues with page id

If i have 10 data in page=1 in pagination,another page having i.e page=2
having another 10 data.and after that page=3 doesn't contain any data.if i
select previous button then that page goes in page-1,page=-2.....and if i
press next button,it will also going on like page=2,page=3 and so on.So
how to disable prev and next button if the record is no longer available
???
<?php
include("config.php");
$start = 0;
$per_page = 5;
if(!isset($_GET['page'])){
$page = 1;
}
else{
$page = $_GET['page'];
}
if($page<=1)
$start = 0;
else
$start = $page * $per_page - $per_page;
$sql="select id,question,correctAnswer,category
from math order by id";
$num_rows = mysql_num_rows(mysql_query($sql));
$num_pages = $num_rows / $per_page;
$sql .= " LIMIT $start, $per_page";
$result=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result))
{?>
.......
........
<?php
$prev = $page - 1;
$next = $page + 1;
echo "<a href='?page=$prev'>prev</a> ";
echo " <a href='?page=$next'>next</a> ";
?>

No comments:

Post a Comment