function genpage(&$sql,$page_size=10 )
{
global $pages,$sums,$eachpage,$page; //Total number of pages, total records, number of pages, current page
$page = $_GET["page"];
if($page ==0)$page =1;
$eachpage = $page_size;
$pagesql = strstr($sql," from ");
$pagesql = "select count (*) as ids ".$pagesql;
$conn = mysql_query($pagesql) or die(mysql_error());
if($rs = mysql_fetch_array($conn))$sums = $rs[0 ];
$pages=ceil($sums/$eachpage);
if($pages==0)$pages=1;
$startpos = ($page-1)*$eachpage;
$sql .=" limit $startpos,$eachpage ";
}
//Show paging
function showpage()
{
global $pages,$sums, $eachpage,$page; //Total number of pages, total records, number of each page, current page, other parameters
$link=$_SERVER['PHP_SELF'];
echo "Record".$sums." :".$eachpage." ";
echo "Number of pages".$page."/".$pages." ";
$p_head=$page-5;
if($p_head< =0)$p_head=1; //First 5 of the page number cycle start count
$p_end=$page+5;
if($p_end>$pages)$p_end=$pages; //End of page number cycle Count last 5
echo "[
Homepage] ";
for($i=$p_head;$i<=$p_end;$ i++)
{
if($i!=$page)
echo "
[$i] ";
else
echo "
[$i] ";
}
echo " [
Last page]";
}
?>