Home >Backend Development >PHP Tutorial >PHP paging function, best paging function_PHP tutorial
PHP paging function backup, date 2011-09-25, fixed several issues.
(1) When the total number of pages is 0, there are many calculation problems.
(2) When the current page is the last page, the calculation error occurs.
(3) Problem when the total number of pages is small and the number of floating pages.
view plain
//New paging function
function fenye($fenyeurl,$page,$totalnum,$perpage,$rewrite=0){
$page = max($page,1);
$totalpage = ceil($totalnum/$perpage);
$rangepage = 6;
$startpage = max(1,$page - $rangepage);
$endpage = min($totalpage,$startpage+$rangepage*2 - 1);
$startpage = min($startpage,$endpage - $rangepage*2 + 1);
if($startpage < 1) $startpage = 1;
$fileext = $rewrite ? '.html':'';
$html = '
Author "default7"