php下的一个分页类
这个分页类,参考了慕课网和燕十八的分页类。
成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:做网站、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的上党网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
慕课网分页类学习网址:http://www.imooc.com/learn/419
效果图:
class page{
public $cpage; //传入的页码
public $totalnum; //总的记录数,数据
public $total_page; //总页数
public $per_page = 10; //每页的记录数
public $showpage = 5; //页码条显示的页码个数
public $pageoffset; //页码条偏移的页码个数
public $pageup; //上一页
public $pagedown; //下一页
public $start=1; //开始页码
public $end; //结束页码
public $fycod = array();
//初始化各个参数
public function __construct($cpage,$totalnum){
$this->cpage = $cpage;
$this->totalnum = $totalnum;
$this->pageoffset = ($this->showpage-1)/2;
$this->total_page = $this->totalnum/10;
$this->end = $this->total_page;
//总页数
$this->total_page = ceil($this->totalnum/$this->per_page);
}
//返回总的页数
public function gettotal_page(){
return $this->total_page;
}
//返回每页的记录数
public function getper_page(){
return $this->per_page;
}
//返回当前页
public function getcpage()
{
return $this->cpage;
}
//修改当前页
public function modcpage($cpage){
$this->cpage = $cpage;
}
//返回上一页
public function getpageup(){
if($this->cpage<=1){
return $this->pageup = 1;
}
return $this->pageup = $this->cpage -1;
}
//返回下一页
public function getpagedown(){
if($this->cpage < $this->total_page){
return $this->pagedown = $this->cpage+1;
}
}
//返回一个数组,关于页码的各个参数
public function getpages(){
$pages = array();
$pages['total_page'] = $this->total_page;
$pages['per_page'] = $this->per_page;
$pages['cpage'] = $this->cpage;
$pages['pageup'] = $this->getpageup();
$pages['pagedown'] = $this->getpagedown();
$pages['start'] = $this->start;
$pages['end'] = $this->end;
$pages['pageoffset'] = $this->pageoffset;
$pages['showpage'] = $this->showpage;
return $pages;
}
//分页代码函数,返回一个数组,作用:分页的页码数
public function getfycod(){
if($this->cpage > $this->pageoffset){
$this->start = $this->cpage - $this->pageoffset;
$this->end = $this->total_page > $this->cpage + $this->pageoffset ? $this->cpage + $this->pageoffset : $this->total_page;
}else{
$this->start = 1;
$this->end = $this->total_page > $this->showpage ? $this->showpage : $this->total_page;
}
if($this->cpage + $this->pageoffset > $this->total_page){
$this->start = $this->start - ($this->cpage + $this->pageoffset - $this->end);
}
for($i=$this->start;$i<=$this->end;$i++){
$this->fycod[] = $i;
}
return $this->fycod;
}
}
网页名称:php下的一个分页类
文章起源:http://scyanting.com/article/ihsssi.html