Php Generic paging code. Php Generic paging code this is a php paging code used. we summarize the special paging code and write a php Generic paging class which is easy to use and easy to understand. Php Generic paging code this is a php paging code used. we summarize the special paging code and write a php Generic paging class which is easy to use and easy to understand.
Class pidepage {// 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-> initpidepage (); // initialize the paging class
// Echo ','. $ this-> displaypg;
}
// Initialize the paging class
Private function initpidepage (){
// 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; // w 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 www. bKjia. c0m.
$ 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 {
$ Commonnav. = 'previous page ';
}
If ($ this-> nextpg <= $ this-> lastpg ){
$ Commonnav. = 'URL. '='. $ this-> nextpg. '"class =" compagestyle "> ';
} Else {
$ Commonnav. = 'next page ';
}
$ Commonnav. = 'URL. '='. $ this-> lastpg. '"class =" compagestyle "> end page'; // display the link to the end page
Return $ commonnav;
}
// Retrieve the navigation page, for example, page n
Public function getjumppagenav (){
//$ Jumpnav = 'to the nthUrl. '= "+ this. value'>'." n ";
For ($ I = 1; $ I <= $ this-> lastpg; $ I ++ ){
If ($ I = $ this-> page) {// use the current page number as the default option.
$ Jumpnav. =''. $ I .''. "N ";
} Else {
$ Jumpnav. =''. $ I .''. "N ";
}
}
$ Jumpnav. ='Page, Total '. $ this-> lastpg.' page ';
Return $ jumpnav;
}
// Retrieve all paging navigation
Public function getallpagenav (){
$ Temp = $ this-> getpageinfo (). $ this-> getcommonpagenav (). $ this-> getjumppagenav ();
Return $ temp;
}
// Obtain the record to be displayed on the current page, which is limited in the database tutorial, for example, 0-9
Public function getlimitstr (){
// Echo $ this-> page;
// Echo $ this-> firstcount;
// Echo $ this-> dispalypg;
$ Temp = $ this-> firstcount. ','. $ this-> displaypg;
// Echo $ temp;
Return $ temp;
}
}