- Class Page {
- Protected $ each_disNums; // Number of Entries displayed on each page
- Protected $ nums; // total number of entries
- Protected $ current_page; // the currently selected page
- Protected $ sub_pages; // Number of pages displayed each time
- Protected $ pageNums; // total number of pages
- Protected $ page_array = array (); // used to construct an array of pagination
- Protected $ subPage_link; // The link of each page
- Protected $ subPage_type; // display page type
- Protected $ houz; // suffix
- /*
- _ Construct is the SubPages Constructor used to automatically run classes when they are created.
- @ $ Each_disNums number of entries per page
- @ Nums total number of entries
- @ Current_num the selected page
- @ Sub_pages the number of pages displayed each time
- @ SubPage_link: the link of each page
- @ SubPage_type: type of the display page
- Normal paging mode when @ subPage_type = 1
- Example: a total of 4523 records are displayed. 10 records are displayed on each page. Currently, page 1/453 [Homepage] [Previous Page] [Next Page] [last page]
- Classic paging style when @ subPage_type = 2
- Example: current page 1/453 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last page]
- */
- Function _ construct ($ each_disNums, $ nums, $ current_page, $ sub_pages, $ subPage_link, $ subPage_type, $ houz = ''){
- $ This-> 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 );
- $ This-> houz = $ houz;
- // Echo $ this-> pageNums. "--". $ this-> sub_pages;
- }
- /*
- _ Destruct: a destructor called when the class is not in use. This function is 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 );
- }
- /*
- The 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 ();
- }
- }
- /*
- The function used to initialize the array that creates pagination.
- */
- 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_array [$ I] = $ I + 1;
- }
- } Elseif ($ this-> current_page <= $ this-> pageNums & $ this-> current_page> $ this-> pageNums-$ this-> sub_pages + 1 ){
- For ($ I = 0; $ I
- $ Current_array [$ I] = ($ this-> pageNums)-($ this-> sub_pages) + 1 + $ I;
- }
- } Else {
- For ($ I = 0; $ I
- $ Current_array [$ I] = $ this-> current_page-2 + $ I;
- }
- }
- }
- Return $ current_array;
- }
- /*
- Construct normal mode paging
- A total of 4523 records are displayed. 10 records are displayed on each page. Currently, page 1/453 [Homepage] [Previous Page] [Next Page] [last page]
- */Bbs.it-home.org
- Function subPageCss1 (){
- $ SubPageCss1Str = "";
- $ SubPageCss1Str. = "total". $ this-> nums. "records ,";
- $ SubPageCss1Str. = "displayed on each page". $ this-> each_disNums ,";
- $ SubPageCss1Str. = "current section". $ this-> current_page. "/". $ this-> pageNums. "page ";
- If ($ this-> current_page> 1 ){
- $ FirstPageUrl = $ this-> subPage_link. "1". $ this-> houz;
- $ PrewPageUrl = $ this-> subPage_link. ($ this-> current_page-1). $ this-> houz;
- $ SubPageCss1Str. = "[Homepage]";
- $ SubPageCss1Str. = "[previous page]";
- } Else {
- $ SubPageCss1Str. = "[Homepage]";
- $ SubPageCss1Str. = "[previous page]";
- }
- If ($ this-> current_page <$ this-> pageNums ){
- $ LastPageUrl = $ this-> subPage_link. $ this-> pageNums. $ this-> houz;
- $ NextPageUrl = $ this-> subPage_link. ($ this-> current_page + 1). $ this-> houz;
- $ SubPageCss1Str. = "[Next Page]";
- $ SubPageCss1Str. = "[last page]";
- } Else {
- $ SubPageCss1Str. = "[Next Page]";
- $ SubPageCss1Str. = "[last page]";
- }
- Return $ subPageCss1Str;
- }
- /*
- Create pagination in 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. = "total [". $ this-> nums. "] Current section ". $ this-> current_page. "/". $ this-> pageNums. "page ";
- If ($ this-> current_page> 1 ){
- $ FirstPageUrl = $ this-> subPage_link. "1". $ this-> houz;
- $ PrewPageUrl = $ this-> subPage_link. ($ this-> current_page-1). $ this-> houz;
- $ SubPageCss2Str. = "[Homepage]";
- $ SubPageCss2Str. = "[previous page]";
- } Else {
- $ SubPageCss2Str. = "[Homepage]";
- $ SubPageCss2Str. = "[previous page]";
- }
- $ A = $ this-> construct_num_Page ();
- For ($ I = 0; $ I
- $ S = $ a [$ I];
- If ($ s ==$ this-> current_page ){
- $ SubPageCss2Str. = "[". $ s. "]";
- } Else {
- $ Url = $ this-> subPage_link. $ s. $ this-> houz;
- $ SubPageCss2Str. = "[". $ s. "]";
- }
- }
- If ($ this-> current_page <$ this-> pageNums ){
- $ LastPageUrl = $ this-> subPage_link. $ this-> pageNums. $ this-> houz;
- $ NextPageUrl = $ this-> subPage_link. ($ this-> current_page + 1). $ this-> houz;
- $ SubPageCss2Str. = "[Next Page]";
- $ SubPageCss2Str. = "[last page]";
- } Else {
- $ SubPageCss2Str. = "[Next Page]";
- $ SubPageCss2Str. = "[last page]";
- }
- Return $ subPageCss2Str;
- }
- /*
- Construct ajax pagination in classic mode
- Current page 1/453 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last page]
- */
- Function subPageCss3 ($ fun = '', $ v = 'n '){
- $ SubPageCss2Str = "";
- $ SubPageCss2Str. = "total [". $ this-> nums. "] Current section ". $ this-> current_page. "/". $ this-> pageNums. "page ";
- If ($ this-> current_page> 1 ){
- // $ FirstPageUrl = $ this-> subPage_link. "1 ";
- $ PrewPageUrl = $ this-> current_page-1;
- $ SubPageCss2Str. = "[Homepage]";
- $ SubPageCss2Str. = "[previous page]";
- } Else {
- $ SubPageCss2Str. = "[Homepage]";
- $ SubPageCss2Str. = "[previous page]";
- }
- $ A = $ this-> construct_num_Page ();
- For ($ I = 0; $ I
- $ S = $ a [$ I];
- If ($ s ==$ this-> current_page ){
- $ SubPageCss2Str. = "[$ s]";
- } Else {
- $ SubPageCss2Str. = "[$ s]";
- }
- }
- If ($ this-> current_page <$ this-> pageNums ){
- $ LastPageUrl = $ this-> pageNums;
- $ NextPageUrl = $ this-> current_page + 1;
- $ SubPageCss2Str. = "[Next Page]";
- $ SubPageCss2Str. = "[last page]";
- } Else {
- $ SubPageCss2Str. = "[Next Page]";
- $ SubPageCss2Str. = "[last page]";
- }
- Return $ subPageCss2Str;
- }
- }
- ?>
Usage: instantiate this page class, $ list = new Page (how many pieces of data per page, total amount of data, current Page, used to construct an array of pages, each page link, display the type and suffix of the Page. for example, $ list = new page (, '/zjjz/', '); echo $ Page = $ list-> subPageCss2 (); it will be displayed: the current page 1/100 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last Page] each connection is/zjjz/1.html, /zjjz/2.html ....... You can combine the links of each page as needed to achieve pseudo-static.
While ajax paging is $ List = new Page ($ pagesize, $ areaAllNumber, $ current_page, 10, ", 3); $ url = $ val1 .','. $ val2; // The value to be passed in the js function to be triggered. $ page = $ list-> subPageCss3 ('checkproducts', $ url ); // The first parameter is the js function to be triggered. To achieve the ajax paging effect.
There is also a subPageCss1 that contains a total of 4523 records, each page shows 10, the current 1/453 page [Homepage] [Previous Page] [Next Page] [last Page] this simple style, it also supports pseudo-static. |