Home >Backend Development >PHP Tutorial >Good PHP paging class_PHP tutorial

Good PHP paging class_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:59:49781browse

class Pager{
//Generated page number (actually it doesn’t matter)
var $pageNumber='';

//Total number of items to be classified
var $totalItems=0;
//Data connection related
var $conn;
var $sql;
//Display several items per page
var $itemsPerPage=3;

//Total number of pages
var $totalPageNumber=0;
//Current page number!
var $currentPageNumber=1;

//Several page numbers displayed on one page
var $length=10;


//URL that needs pagination
var $url='';
function Pager($conn,$sql,$currentPageNumber,$itemsPerPage,$length,$url){
$this->currentPageNumber=$currentPageNumber;
$this->conn=$conn;
$this->sql=$sql;
$this->itemsPerPage=$itemsPerPage;
$this->length=$length;
$this->url=$url;
$this->url.=(stristr($this->url,'?')!=false)?'&':'?'; //If there is "?" in the Url, add "&" if there is no Add "?"
$this->getTotalPageNumber();
}
function getTotalItems(){
//for adodb
$rs=$this->conn->Execute($this->sql);
$this->totalItems=$rs->RecordCount();
return $this->totalItems;
}
function getTotalPageNumber(){
$this->totalPageNumber=ceil($this->getTotalItems()/$this->itemsPerPage);
return $this->totalPageNumber;
}

//LIMIT start in SQL, starting value in length
function getLimitStart(){
$start=($this->currentPageNumber-1)*$this->itemsPerPage;
return $start;
}
//LIMIT start in SQL, length
in length function getLimitItems(){
return $this->itemsPerPage;
}
function getRsPerPage(){
$modiSQL=$this->sql." limit ".$this->getLimitStart()." ,".$this->getLimitItems();
//I am using adodb
$modiRS=$this->conn->Execute($modiSQL);
$arr=$modiRS->GetArray();
return $arr;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631886.htmlTechArticle?php class Pager{ //Generated page number (actually it doesn’t matter) var $pageNumber=''; //The total number of items that need to be classified var $totalItems=0; //Data connection related var $conn; var $sql; //Each page...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn