Php simple paging class _ PHP Tutorial

Source: Internet
Author: User
Php simple paging class .? Php *** paging class ** 2011831 * kcj ** classPage {private $ total; query the total data record private $ page; current page private $ pagesize; number of lines displayed per page priv /**
* Paging class
* 2011/8/31
* Kcj
**/
Class Page {
Private $ total; // query the total data records
Private $ page; // current page
// Private $ pagesize; // Number of Entries displayed on each page
Private $ pagenum; // total number of pages
Private $ num; // number of records per page
Private $ offset; // number of start offsets of records retrieved from the database

Function _ construct ($ total, $ page = 1, $ num = 5 ){
$ This-> total = $ total;
$ This-> page = $ page;
$ This-> num = $ num;
$ This-> pagenum = $ this-> getPageNum ();
$ This-> offset = $ this-> getOffset ();
}
Private function getPageNum (){
Return ceil ($ this-> total/$ this-> num );
}
Private function getNextPage () {// Next page
If ($ this-> page ==$ this-> pagenum ){
Return false;
} Else {
Return $ this-> page + 1;
}
}
Private function getPrevPage (){
If ($ this-> page = 1) {// Previous page
Return false;
} Else {
Return $ this-> page-1;
}
}
Private function getOffset (){
Return ($ this-> page-1) * $ this-> num;
}
Private function getStartNum (){
If ($ this-> total = 0 ){
Return 0;
} Else {
Return $ this-> offset + 1;
}
}
Private function getEndNum (){
Return min ($ this-> offset + $ this-> num, $ this-> total );
}
Public function getPageInfo (){
$ PageInfo = array (
"Row_total" => $ this-> total,
"Row_num" => $ this-> num,
"Page_num" => $ this-> getPageNum (),
"Current_page" => $ this-> page,
"Row_offset" => $ this-> getOffset (),
"Next_page" => $ this-> getNextPage (),
"Prev_page" => $ this-> getPrevPage (),
"Page_start" => $ this-> getStartNum (),
"Page_end" => $ this-> getEndNum ()
);
Return $ pageInfo;
}
}
?>

From chaojie2009

Http://www.bkjia.com/PHPjc/478369.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478369.htmlTechArticle? Php/*** paging class * 2011/8/31 * kcj **/class Page {private $ total; // query the total data record private $ page; // Current page/private $ pagesize; // The number of entries displayed per page priv...

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.