Study goal: Makes a paging demonstration

The key was uses in SQL sentence limit to define the demonstration the record from several to several. We need a record current page variable $page, but also needs altogether record to count $num

Regarding $page, if does not have us to let its =0, if has <0 to let its also =0, if surpassed the total number of pages to let he = total number of pages.

$execc= ” select count(*) from tablename “;
$resultc=mysql_query($execc);
$rsc=mysql_fetch_array($resultc);
$num=$rsc[0];

This may obtain the record total
ceil($num/10)), if page of 10 record, this is the total number of pages

Therefore may such write
if (empty ($_GET [’page’]))
{
$page=0;
}
else
{
$page=$_GET [’page’];
if($page<0)$page=0;
if($page>=ceil($num/10))$page=ceil($num/10)-1; // because page is from 0 starts, therefore wants - 1
}

Such $exec may such write $exec= ” select * from tablename limit “. ($page*10).”, 10 “;
a // page is 10 records

Finally we need to do are several connections:
<a href= ” xxx.php? page=0 ” >FirstPage</a>
<a href= ” xxx.php? page=<? = ($page-1)? > ” >PrevPage</a>
<a href= ” xxx.php? page=<? = ($page+1)? > ” >NextPage</a>
<a href= ” xxx.php? page=<? =ceil($num/10)-1? > ” >LastPage</a>