Applicable to PHP paging code and usage

Source: Internet
Author: User
The useful PHP paging code and usage code are as follows: & lt ;? PhpclassPage {?? Private $ total ;??? // Total records ?? Private $ pagesize ;?? // How many entries are displayed on each page ?? PHP paging code and usage of priv

The class code is as follows:

 Total = $ _ total? $ _ Total: 1 ;??? $ This-> pagesize =$ _ pagesize ;?? $ This-> pagenum = ceil ($ this-> total/$ this-> pagesize );??? $ This-> page = $ this-> setPage ();??? $ This-> limit = "LIMIT". ($ this-> page-1) * $ this-> pagesize. ", $ this-> pagesize ";??? $ This-> url = $ this-> setUrl ();??? $ This-> bothnum = 2 ;??}???? // Interceptor ?? Private function _ get ($ _ key ){??? Return $ this-> $ _ key ;??}???? // Obtain the current page number ?? Private function setPage (){??? If (! Empty ($ _ GET ['Page']) {??? If ($ _ GET ['Page']> 0 ){????? If ($ _ GET ['Page']> $ this-> pagenum ){?????? Return $ this-> pagenum ;?????} Else {?????? Return $ _ GET ['Page']; ??? }????} Else {????? Return 1 ;????}???} Else {???? Return 1 ;???}??}????? // Obtain the address ?? Private function setUrl (){??? $ _ Url = $ _ SERVER ["REQUEST_URI"]; ??? $ _ Par = parse_url ($ _ url );??? If (isset ($ _ par ['query']) {??? Parse_str ($ _ par ['query'], $ _ query );???? Unset ($ _ query ['Page']); ??? $ _ Url = $ _ par ['path']. '? '. Http_build_query ($ _ query );???}??? Return $ _ url ;??}?? // Digital directory ?? Private function pageList (){??? For ($ I = $ this-> bothnum; $ I >=1; $ I --){???? $ _ Page = $ this-> page-$ I ;???? If ($ _ page <1) continue ;???? $ _ Pagelist. = 'URL. '& page ='. $ _ page. '">'. $ _ page .'';???}??? $ _ Pagelist. = ''. $ this-> page .'';??? For ($ I = 1; $ I <= $ this-> bothnum; $ I ++ ){???? $ _ Page = $ this-> page + $ I ;???? If ($ _ page >$ this-> pagenum) break ;???? $ _ Pagelist. = 'URL. '& page ='. $ _ page. '">'. $ _ page .'';???}??? Return $ _ pagelist ;??}???? // Homepage http://ini.iteye.com/??private Function first (){??? If ($ this-> page >$ this-> bothnum + 1 ){???? Return 'URL. '"> 1 ...';???}??}???? // Previous page ?? Private function prev (){??? If ($ this-> page = 1 ){???? Return 'previous page ';???}??? Return 'URL. '& page ='. ($ this-> page-1). '"> Previous page ';??}???? // Next page ?? Private function next (){??? If ($ this-> page ==$ this-> pagenum ){???? Return 'next page ';???}??? Return 'URL. '& page ='. ($ this-> page + 1). '"> Next page ';??}???? // End page ?? Private function last (){??? If ($ this-> pagenum-$ this-> page> $ this-> bothnum ){???? Return '... url. '& page = '. $ this-> pagenum. '"> '. $ this-> pagenum. '';???}??}???? // Paging information ?? Public function showpage (){??? $ _ Page. = $ this-> first ();??? $ _ Page. = $ this-> pageList ();??? $ _ Page. = $ this-> last ();??? $ _ Page. = $ this-> prev ();??? $ _ Page. = $ this-> next ();??? Return $ _ page; ??? }?}?>

?? Instructions for use:

 

? Shows the paging style :?



?

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.