Home  >  Article  >  Backend Development  >  PHP paging function, best paging function_PHP tutorial

PHP paging function, best paging function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:45:561041browse

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 = '

    ';
    $html .= '
  • Homepage
  • ';
    $html .= $page > 1 ? '
  • Previous page
  • ':'';
    for($i = $startpage;$i <= $endpage;$i++){
    $html .= '
  • '.$i.'
  • ';
    If($i == $totalpage) break;
    }  
    $html .= $page < $totalpage ? '
  • Next page $html .= '
  • Last page
  • ';
    $html .= '
';

return $html;
}

Author "default7"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478621.htmlTechArticlePHP 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. ...
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