PHP paging function, best paging function _ PHP Tutorial

Source: Internet
Author: User
PHP paging function, the best paging function. PHP paging function backup, date, fixed several issues. (1) when the total number of pages is 0, there is an extra computing problem. (2) The calculation error occurs when the current page is the last page. PHP paging function backup, date, fixed several issues.

(1) when the total number of pages is 0, there is an extra computing problem.

(2) The calculation error occurs when the current page is the last page.

(3) problems when the total number of pages is small and the number of floating pages is large.

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"

Bytes. (1) when the total number of pages is 0, there is an extra computing problem. (2) The calculation error occurs when the current page is the last page ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.