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

PHP paging function, best paging function_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:45:56
Original
1139 people have browsed it

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 of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template