Home >Backend Development >PHP Tutorial >Another PHP paging class implementation code_PHP tutorial

Another PHP paging class implementation code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:42:15806browse

Copy code The code is as follows:

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]";
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320975.htmlTechArticleCopy the code code as follows: ?php function genpage( //Total number of pages, total records, number of pages, current Page$page = $_GET["page"]; if($page ==0)$page =1; $eachpage = $page_size; $pagesql = s...
Statement:
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