Copy code The code is as follows:
function genpage(&$sql,$page_size=10)
{
global $pages,$sums,$eachpage,$page; //Total page Number, total records, number of pages per page, 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 pages Number, total records, number of pages, 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; //The first 5 pages of the page number cycle
$p_end =$page+5;
if($p_end>$pages)$p_end=$pages; //5
echo "[Homepage a>] ";
for($i=$p_head;$i<=$p_end;$i++)
{
if($i!=$page)
echo "[$i] ";
else
echo "[$i] ";
}
echo " [< a href=$link?page=$pages>Last page]";
}
?>
The above introduces One Person's Loneliness, Two Persons' Fault by He Yihang. Another PHP paging class implementation code, including One Person's Loneliness, Two Persons' Fault by He Yihang. I hope it will be helpful to friends who are interested in PHP tutorials.