PHP Perfect Pagination class Program _php tutorial

Source: Internet
Author: User
This article introduces this PHP page class support next page, next page, home page and so on all the pagination to have all, there is a need for students can refer to the next ha.
The code is as follows Copy Code

/************************************************************************************
* Perfect pagination class, can customize the pagination (than Gao teacher's perfect Ha, O (∩_∩) o haha ~) *
************************************************************************************
* Copyright (C) 2011-2012 Beihai love letter-A programmer's blog, and All rights reserved. *
*
* **********************************************************************************
* $Author: Beihai love Letter (hackmyth@163.com) $ *
* $Date: 2011-07-18 10:00:00 $ *
* **********************************************************************************/

Class page{

Private $total; Total number of data bars
Private $listRows; Show number of bars per page
Private $limit; Limit number of bars
Private $pageNum; Total pages
Private $page; Current page
Private $config =array (' head ' = "record", "Prev" and "prev", "Next" = "Next", "first" = "Home", "last" and "End");

/**
* Construction method, you can set the properties of the paging class
* @param int $total Calculate the total number of records for pagination
* @param int $listRows Optional, default number of records to display per page
*
*/
Public function __construct ($total, $listRows =10) {

$this->total= $total;
$this->listrows= $listRows;
$this->pagenum=ceil ($this->total/$this->listrows); Get Total Pages
if ($_get[' page ']> $this->pagenum) {//Prevent over-bounds
$_get[' page ']= $this->pagenum;
}
$this->page=!empty ($_get[' page ')? $_get[' page ']: "1"; Current page
$this->limit= $this->setpage (); Page out formula
}

Public Function __get ($args) {

if ($args = = ' limit ') {//filter illegal request
return $this->limit;
}
return null;
}

Calculate a page-out formula
Private Function Setpage () {

Return "Limit". ($this->page-1) * $this->listrows. ",". $this->listrows;

}

Previous page
Private Function prev () {
Return "page-1)." > ". $this->config[' prev ').";
}

Next page
Private function Next () {
Return "page+1)." > ". $this->config[' next ').";
}

Home
Private Function First () {
Return "". $this->config[' first ']. "";
}

Last
Private Function Last () {
Return "Pagenum)." > ". $this->config[' last '].";
}

List of pages

Private Function PageList () {

$lists. = ';
for ($i =1; $i < $this->pagenum; $i +) {

$lists. = "$i";
}
return $lists;
}


Public Function Fpage ($display =array (1,2,3,4,5)) {

$html [1]=]. $this->total. $this->config[' head ';
$html [2]= $this->prev (); Previous page
$html [3]= $this->next (); Next page
$html [4]= $this->first (); Home
$html [5]= $this->last (); Last
$html [6]= $this->pagelist (); List
$fpage = ";
foreach ($display as $index) {

$fpage. = $html [$index];
}
return $fpage;
}


}

http://www.bkjia.com/PHPjc/631648.html www.bkjia.com true http://www.bkjia.com/PHPjc/631648.html techarticle This article introduces this PHP page class support next page, next page, home page and so on all the pagination to have all, there is a need for students can refer to the next ha. Code to copy code like this? PHP/* ...

  • Related Article

    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.