Another php paging code

Source: Internet
Author: User
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 :-)

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.