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 :?
?