Home >Backend Development >PHP Tutorial >PHP digital pagination class code_PHP tutorial
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
*/