Home  >  Article  >  Backend Development  >  PHP digital pagination class code_PHP tutorial

PHP digital pagination class code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:54:45771browse

The following is a PHP digital paging code. The code has been encapsulated. Friends who need it can refer to it. The main principle of paging is to get the current page, then determine how many records there are on the page and divide them to get the total records. It's that simple.

The following is a PHP tutorial digital paging code. The code has been encapsulated. Friends in need can refer to it. The main principle of paging is to get the current page, then determine how many records there are on the page and divide them to get the total records. It's that simple.

function getnavhtml($pagenum,$pagesize,$rowcount,$navurl){
$pagecount = (int)($rowcount/$pagesize); //Total number of pages
if ($rowcount % $pagesize >0){
$pagecount++;
}
if ($pagenum>$pagecount){
$pagenum = 1;
}
$firstnav = "Homepage ";
$lastnav = "Last page ";
$prevnav="";
$nextnav="";
if ($pagenum>1){
$navpagenum = $pagenum-1;
$prevnav = "Previous page ";
}
if ($pagenum<$pagecount && $pagecount>1){
$navpagenum = $pagenum+1;
$nextnav = "Next page ";
}
$amongnav="";

//Key loop

for ($i=1;$i<=5;$i++){
$navpagenum = $pagenum+ $i-3;
if ($navpagenum>0 && $navpagenum<=$pagecount){
$navcss tutorial = $navpagenum == $pagenum?" class="hover"":"";
$amongnav.="{$navpagenum} ";
}
}
return $firstnav.$prevnav.$amongnav.$nextnav.$lastnav." ".$pagenum."/".$pagecount." There are [".$rowcount."] pieces of data";
}
}

/**
* Get page number navigation html
* @param $pagenum: current page number
* @param $pagesize: number of pages
* @param $rowcount: Total number of records
* @param $navurl: link page url
*/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631726.htmlTechArticleThe following is a PHP digital paging class code. The code has been encapsulated. Friends in need can refer to it. Use it. The main principle of paging is to get the current page and then determine how many pages there are...
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