Simple, convenient, and fully functional php paging class

Source: Internet
Author: User
Paging code & lt ;? PhpclassSubPages {private $ each_disNums; // Number of items displayed on each page private $ nums; // total number of items private $ current_page; // the currently selected page private $ sub_pages; // The number of pages displayed each time is private $... "Paging code Each_disNums = intval ($ each_disNums); $ this-> nums = intval ($ nums); if (! $ Current_page) {$ this-> current_page = 1;} else {$ this-> current_page = intval ($ current_page);} $ this-> sub_pages = intval ($ sub_pages ); $ this-> pageNums = ceil ($ nums/$ each_disNums); $ this-> subPage_link = $ subPage_link; $ this-> show_SubPages ($ subPage_type ); // echo $ this-> pageNums. "--". $ this-> sub_pages;}/* _ destruct destructor, called when the class is not in use and used to release resources. */Function _ destruct () {unset ($ each_disNums); unset ($ nums); unset ($ current_page); unset ($ sub_pages); unset ($ pageNums ); unset ($ page_array); unset ($ subPage_link); unset ($ subPage_type);}/* show_SubPages function is used in the constructor. And used to determine what the page looks like */function show_SubPages ($ subPage_type) {if ($ subPage_type = 1) {$ this-> subPageCss1 ();} elseif ($ subPage_type = 2) {$ this-> subPageCss2 () ;}/ * is used to initialize a paging array. */Function initArray () {for ($ I = 0; $ I <$ this-> sub_pages; $ I ++) {$ this-> page_array [$ I] = $ I;} return $ this-> page_array;}/* construct_num_Page this function is used to construct display entries even if: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] */function construct_num_Page () {if ($ this-> pageNums <$ this-> sub_pages) {$ current_array = array (); for ($ I = 0; $ I <$ this-> pageNums; $ I ++) {$ current_array [$ I] = $ I + 1 ;}} else {$ current_array = $ this-> initArray (); if ($ this-> current_page <= 3) {for ($ I = 0; $ I Current_page <= $ this-> pageNums & $ this-> current_page> $ this-> pageNums-$ this-> sub_pages + 1) {for ($ I = 0; $ I PageNums)-($ this-> sub_pages) + 1 + $ I ;}} else {for ($ I = 0; $ I Current_page-2 + $ I ;}}return $ current_array;}/* construct a total of 4523 records for normal mode pagination, 10 records per page, current page 1/453 [Homepage] [Previous Page] [Next Page] [last Page] */function subPageCss1 () {$ subPageCss1Str = ""; $ subPageCss1Str. = "total ". $ this-> nums. "record,"; $ subPageCss1Str. = "display on each page ". $ this-> each_disNums. ","; $ subPageCss1Str. = "current number ". $ this-> current_page. "/". $ this-> pageNums. "page"; if ($ this-> current_page> 1) {$ firstPageUrl = $ this-> subPage_link. "1"; $ prewPageUrl = $ this-> subPage_link. ($ this-> current_page-1); $ subPageCss1Str. = "[Homepage]"; $ subPageCss1Str. = "[previous page]";} else {$ subPageCss1Str. = "[Homepage]"; $ subPageCss1Str. = "[previous page]";} if ($ this-> current_page <$ this-> pageNums) {$ lastPageUrl = $ this-> subPage_link. $ this-> pageNums; $ nextPageUrl = $ this-> subPage_link. ($ this-> current_page + 1); $ subPageCss1Str. = "[Next Page]"; $ subPageCss1Str. = "[last page]";} else {$ subPageCss1Str. = "[Next Page]"; $ subPageCss1Str. = "[last page]";} echo $ subPageCss1Str ;} /* create a page in the classic mode. Current page 1/453 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last Page] */function subPageCss2 () {$ subPageCss2Str = ""; $ subPageCss2Str. = "current number ". $ this-> current_page. "/". $ this-> pageNums. "page"; if ($ this-> current_page> 1) {$ firstPageUrl = $ this-> subPage_link. "1"; $ prewPageUrl = $ this-> subPage_link. ($ this-> current_page-1); $ subPageCss2Str. = "[Homepage]"; $ subPageCss2Str. = "[previous page]";} else {$ subPageCss2Str. = "[Homepage]"; $ subPageCss2Str. = "[previous page]" ;}$ a = $ this-> construct_num_Page (); for ($ I = 0; $ I Current_page) {$ subPageCss2Str. = "[". $ s. "]";} else {$ url = $ this-> subPage_link. $ s; $ subPageCss2Str. = "[". $ s. "]" ;}} if ($ this-> current_page <$ this-> pageNums) {$ lastPageUrl = $ this-> subPage_link. $ this-> pageNums; $ nextPageUrl = $ this-> subPage_link. ($ this-> current_page + 1); $ subPageCss2Str. = "[Next Page]"; $ subPageCss2Str. = "[last page]";} else {$ subPageCss2Str. = "[Next Page]"; $ subPageCss2Str. = "[last page]";} echo $ subPageCss2St R ;}}?> Demo code:

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.