码迷,mamicode.com
首页 > Web开发 > 详细

php分页类

时间:2015-08-31 21:33:47      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

<?php

class page
{
private $total; // 总记录数
private $nums;// 每页显示条数
private $pages;//总页数
private $cpage;//当前页
private $url;
public function __construct($total, $nums)
{
$this->total=$total;
$this->nums=$nums;
$this->pages=$this->getPage();
}

//总页数
private function getPage(){
return ceil($this->total/$this->nums);

}
//上一页
private function first(){
$this->cpage=!empty($_GET[‘page‘])?$_GET[‘page‘]:1;
if($this->cpage>1){
$pre=$this->cpage-1;
return ‘<a href="‘.$this->url.‘?page=1">首页</a><a href="‘.$this->url.‘?page=‘.$pre.‘">上一页</a>‘;
}
else {
return "";
}

}
//列表页
private function flist(){
$list="";
$num="4";

for($i=$num;$i>=1;$i--){
$page = $this->cpage - $i;
if($page > 1)
{
$list .= ‘&nbsp;<a href="‘.$this->url.‘?page=‘.$page.‘">‘.$page.‘</a>&nbsp;‘;

}
}
//当前页面
if($this->pages>1){
$list.="&nbsp{$this->cpage}&nbsp";
}

for($i=1;$i<$num;$i++){
$page=$this->cpage+$i;
if($page <= $this->pages)
{
$list .= ‘&nbsp;<a href="‘.$this->url.‘?page=‘.$page.‘">‘.$page.‘</a>&nbsp;‘;
}

else
{
break;

}
}

return $list;

}
//下一页
private function flast(){
if($this->pages>=$this->cpage){
$next=$this->cpage+1;
return ‘<a href="‘.$this->url.‘?page=‘.$next.‘">下一页</a><a href="‘.$this->url.‘?page=‘.$this->pages.‘">末页</a>‘;
}


}
public function fpage(){


return "总记录数 {$this->first()} {$this->flist()} {$this->flast()}" ;
}
}

php分页类

标签:

原文地址:http://www.cnblogs.com/w84036937/p/4774074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!