Copy CodeThe code is as follows:
Function Genpage (& $sql, $page _size=10)
{
Global $pages, $sums, $eachpage, $page; Total pages, total records, per 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 pagination
function ShowPage ()
{
Global $pages, $sums, $eachpage, $page; Total pages, total records, each page, current page, other parameters
$link =$_server[' php_self '];
echo "Record". $sums. ":". $eachpage. " ";
echo "pages". $page. " /". $pages." ";
$p _head= $page-5;
if ($p _head<=0) $p _head=1; Number of page loops start 5 first
$p _end= $page +5;
if ($p _end> $pages) $p _end= $pages; Number of 5 After the end of a page loop
echo "[Home]";
for ($i = $p _head; $i <= $p _end; $i + +)
{
if ($i! = $page)
echo "[$i]";
Else
echo "
[$i]
";
}
echo "[Last]";
}
?>
http://www.bkjia.com/PHPjc/320975.html www.bkjia.com true http://www.bkjia.com/PHPjc/320975.html techarticle Copy the code as follows:? PHP function Genpage (//Total pages, total records, per page, current page $page = $_get["page"], if ($page ==0) $page =1; $eachpage = $page _si Ze $pagesql = S ...