?php
class pageclass{
private $total; //總記錄
private $pagesize; //每頁顯示多少條
private $limit; //limit
private $page; //當(dāng)前頁
private $pagenum; //總頁碼
private $url; //地址
public function __construct($_total,$_pagesize,$page){
$this->total = $_total ? $_total :1 ; //總條數(shù)
$this->pagesize = $_pagesize; //每頁顯示多少條
$this->page = $page; //當(dāng)前頁碼
$this->pagenum = ceil($this->total / $this->pagesize); //總頁碼
$this->limit = "limit ".($this->page-1)*$this->pagesize.",".$this->pagesize; //分頁語句
$this->url = $this->setUrl(); //地址
}
//分頁語句
public function limit(){
return $this->limit;
}
//當(dāng)前的url地址
public function setUrl(){
$server = $_SERVER['REQUEST_URI'];
$im = explode('/',$server);
if(empty($_SERVER['PATH_INFO'])){
$array = array_splice($im,2,0,array('2'=>'index.php'));
}
$controller = $im[3];
$action = $im[4];
if(empty($_SERVER['PATH_INFO'])){
$servers = "http://".$_SERVER['HTTP_HOST']."/".$im[1]."/".$controller."/".$action."/";
}else{
$servers = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."/".$controller."/".$action."/";
}
return $servers;
//return $im;
}
//首頁
public function first(){
//return $this->page;
if($this->page > 1){
return "a href='".$this->url."page/1'>首頁/a>";
}
}
//上一頁
public function prev(){
if($this->page==1){
$page = 1;
}else{
$page = $this->page-1;
}
if($this->page > 1){
return "a href='".$this->url."page/".$page."'>上一頁/a>";
}else{
return "span class='disabled'>上一頁/span>";
}
}
//下一頁
public function next(){
$page = $this->page+1;
if($this->page $this->pagenum){
if(empty($this->page)){
$pages = $this->page+2;
return "a href='".$this->url."page/".$pages."'>下一頁/a>";
}else{
return "a href='".$this->url."page/".$page."'>下一頁/a>";
}
}else{
return "span class='disabled'>下一頁/span>";
}
}
//尾頁
public function last(){
if($this->page $this->pagenum){
return "a href='".$this->url."page/".$this->pagenum."'>尾頁/a>";
}
}
//分頁
public function showpage(){
$page_ = "";
$page_ .= $this->first();
$page_ .= " ".$this->prev();
$page_ .= " ".$this->next();
$page_ .= " ".$this->last();
return $page_;
}
}
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫操作入門教程》、《php+mysqli數(shù)據(jù)庫程序設(shè)計技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總》