Another php paging code _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Another php paging code. Another php paging code has previously written a lot of php paging classes. But today, I feel like this paging program is very good, simple and practical, and there is no redundant code for proper code, it is a good paging and php paging code that has previously been written in many php paging classes. But today, this paging program is very good, simple, and practical, the code is reasonable and there is no redundant code. it is a good paging function.

Another php Tutorial paging code
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.
*/

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

Paging class, but today I feel like this paging program is very good, simple and practical, and there is no redundant code in the code. it is a good paging...

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.