What's wrong with my paging query? this is page. class. php & lt ;? Phpclass & nbsp; DividePage {// pagination class private & nbsp; $ total; // The total number of records to be displayed. private & nbsp; $ url helps me check the total number of records, what is wrong with the paging class in my query?
This is page. class. php.
Class DividePage {// paging class
Private $ total; // The total number of records to be displayed
Private $ url; // The requested URL
Private $ displaypg; // number of records displayed on each page. by default, 10 records are displayed on each page.
Private $ page; // The current page number.
Private $ lastpg; // The total number of pages, that is, the page number of the last page
Private $ prepg; // Previous Page
Private $ nextpg; // Next page
Private $ firstcount; // The sequence number starting from 0
Private $ startd; // The number of records starting with the number of records.
Private $ stopd; // The number of records whose number ends.
// Constructor
Public function _ construct ($ url, $ total, $ displaypg ){
$ This-> url = $ url; // The requested URL
$ This-> total = $ total; // total number of records
// If ($ displaypg = '')
$ This-> displaypg = $ displaypg; // number of records displayed on each page
$ This-> initDividePage (); // initialize the paging class
// Echo ','. $ this-> displaypg;
}
// Initialize the paging class
Private function initDividePage (){
// Analyze the URL
$ Parse_url = parse_url ($ this-> url); // interpret the URL as an array with fixed key-value pairs
$ Url_query = $ parse_url ['query']; // retrieves the query string from the URL.
If ($ url_query) {// if a query string exists, delete the query field on the current page of the query string, for example, & page = $ page or page = $ page.
Ereg ('(^ | &) page = ([0-9] *)', $ url_query, $ k );
$ This-> page = $ k [2]; // get the value of the current page
$ Url_query = ereg_replace ("(^ | &) page = $ this-> page", '', $ url_query); // delete the query fields on the current page of the query string, for example: & page = $ page or page = $ page
$ This-> url = str_replace ($ parse_url ['query'], $ url_query, $ this-> url); // retain other query strings,
$ This-> page = $ this-> page? $ This-> page: 1; // if the query string does not contain the value of the current page, set the current page to 1.
If ($ url_query) {// if there are other query strings, add the paging query string in the form of & page = $ page
$ This-> url. = '& page ';
} Else {// if no other query string exists, the paging query string is added in the form of page = $ page.
$ This-> url. = 'page ';
}
} Else {// if no query string exists, add? Page = $ page-based paging query string
$ This-> page = 1;
$ This-> url. = '? Page ';
}
$ This-> lastpg = ceil ($ this-> total/$ this-> displaypg); // calculate the total number of pages, that is, the page number of the last page
$ This-> page = min ($ this-> lastpg, $ this-> page); // if the current page is greater than the total number of pages, the current page is the last page
$ This-> prepg = $ this-> page-1; // the previous page is the current page Minus One
$ This-> nextpg = $ this-> page + 1; // ($ this-> page = $ this-> lastpg )? $ This-> lastpg: ($ this-> page + 1); // the next page is the current page plus one. if the current page is the last page, the next page is 0.
$ This-> firstcount = ($ this-> page-1) * $ this-> displaypg; // calculates the number of records starting with the number of records on the current page, starting from 0.
$ This-> startd = $ this-> total? ($ This-> firstcount + 1): 0; // record start number starts from 1
$ This-> stopd = min ($ this-> firstcount + $ this-> displaypg, $ this-> total); // record end number
// Echo $ this-> displaypg;
// Echo $ this-> nextpg. '+ ='. $ this-> lastpg;
}
Public function getPageInfo () {// obtain the basic information of the current page, for example, display 1st-10 records, a total of 23 records.
Return 'display Records '. $ this-> startd.'-'. $ this-> stopd.', total Records '. $ this-> total. ';
}
Public function getCommonPageNav () {// Obtain the usual paging navigation, for example, the last page of the previous page on the homepage
$ Commonnav = '';
If ($ this-> lastpg = 1) {// if there is only one page, return to the paging navigation, exit, do not display the next page, previous page, and so on...
Return $ commonnav;
Break;
}
$ Commonnav = 'URL. '= 1 "class =" compagestyle "> homepage'; // Set the homepage navigation, page = 1
If ($ this-> prepg ){
$ Commonnav. = 'URL. '='. $ this-> prepg. '"class =" compagestyle "> ';
} Else {