I have written a lot of php paging classes before, but today I feel like this paging program is very good, simple and practical, and there is no extra code for proper code. it is a good paging function. Code such...
I have written a lot of php paging classes before, but today I feel like this paging program is very good, simple and practical, and there is no extra code for proper code. it is a good paging function.
| The code is as follows: |
|
|
Class multipage {
Var $ total;
Var $ perpage;
Var $ pages;
Var $ maxpage;
Var $ offset = 9;
Var $ curr_page;
Function init ($ total, $ perpage, $ maxpage) {// initialize the page number
$ This-> total;
$ This-> perpage;
$ This-> maxpage;
$ This-> offset = 9;
}
Function getpagelist () {// retrieve the page List
$ Result_pages = "";
$ This-> pages = ceil ($ this-> total/$ this-> perpage );
If ($ this-> pages> $ this-> maxpage ){
$ From = $ this-> curr_page-$ this-> offset;
If ($ from <1 ){
$ From = 1;
}
$ To = $ from + $ this-> maxpage-1;
If ($ to> $ this-> pages ){
$ To = $ this-> pages;
If ($ to-$ from) <$ this-> maxpage ){
$ From = $ from-1;
}
}
} Else {
$ From = 1;
$ To = $ this-> pages;
}
$ P = 0;
For ($ I = $ from; $ I <= $ to; $ I ++ ){
$ Result_pages [$ p] = $ I;
$ P ++;
}
Return $ result_pages;
}
Function getfirst () {// get the first page
If ($ this-> curr_page> 1 & $ this-> pages> 1 ){
Return 1;
} Else {
Return "";
}
}
Function getlast () {// get the last page
If ($ this-> pages> 1 & $ this-> curr_page <$ this-> pages ){
Return $ this-> pages;
} Else {
Return "";
}
}
Function getprev () {// Previous Page
$ Prevpage = $ this-> curr_page-1;
If ($ prevpage> 0 ){
Return $ prevpage;
} Else {
$ Prevpage = "";
Return $ prevpage;
}
}
Function getnext () {// Next page
$ Nextpage = $ this-> curr_page + 1;
If ($ nextpage <= $ this-> pages ){
Return $ nextpage;
} Else {
$ Nextpage = "";
Return $ nextpage;
}
}
Function gettotal () {// total number of pages
If ($ this-> pages> 0 ){
Return $ this-> pages;
} Else {
Return 1;
}
}
}
// Usage of the paging class
$ Page = new multipage ();
$ Page-> gettotal (); //
$ Page-> getnext (); // Next page |
Address:
Reprinted at will, but please attach the article address :-)