Home > Backend Development > PHP Tutorial > One person's loneliness, two people's fault He Yihang Another PHP paging class implementation code

One person's loneliness, two people's fault He Yihang Another PHP paging class implementation code

WBOY
Release: 2016-07-29 08:41:17
Original
896 people have browsed it

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] ";
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.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template