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]";
}
?>
The above describes a person's loneliness two people of the fault of a flight and a PHP page class implementation code, including a person's lonely two people's fault of the content, I hope that the PHP tutorial interested friends have helped.