<?php
//分页类
class fenye {
protected $totalnum = 0; //总记录
protected $pagenum = 0; //每页记录
protected $totalpage= 0; //总页数
protected $nowpage = 1; //当前页
protected $pageup = 0; //上一页
protected $pagedown = 0; //下一页
protected $firstpage =1; //最前页(首页)
protected $lastpage = 0; //最后一页(尾页)
protected $showpagenum = 10; //显示最大的页码
public function __construct($totalnum,$pagenum=10){
$this->totalnum = $totalnum;
$this->pagenum = $pagenum;
//计算总页数
$this->totalpage = ceil($totalnum/$pagenum);
//初始化最后一页
$this->lastpage = $this->totalpage;
}
//返回总计录
public function gettotalnum()
{
return $this->totalnum;
}
//返回每页记录
public function getpagenum()
{
return $this->pagenum;
}
//返回总页数
public function gettotalpage()
{
return $this->totalpage;
}
//返回当前页
public function getnowpage()
{
return $this->nowpage;
}
//修改当前页
public function setnowpage($nowpage)
{
$this->nowpage = $nowpage;
}
//计算上一页
public function getpageup()
{
if($this->nowpage<=1){
return $this->pageup = 1;
}
return $this->pageup = $this->nowpage -1;
}
//计算下一页
public function getpagedown()
{
if($this->nowpage>=$this->totalpage){
return $this->pagedown = $this->totalpage;
}
return $this->pagedown = $this->nowpage + 1;
}
//修改最大的分页码显示值
public function setshowpagenum($showpagenum)
{
$this->showpagenum = $showpagenum;
}
//返回一组分页标志
public function getpages()
{
$pages = array();
$pages['totalnum'] = $this->totalnum;
$pages['totalpage'] = $this->totalpage;
$pages['nowpage'] = $this->nowpage;
$pages['pagenum'] = $this->pagenum;
$pages['pageup'] = $this->getpageup();
$pages['pagedown'] = $this->getpagedown();
$pages['firstpage'] = $this->firstpage;
$pages['lastpage'] = $this->lastpage;
return $pages;
}
//返回一个分页码
public function getfycod()
{
$nowpage = $this->nowpage; //当前页
$show = $this->showpagenum; //最大页码长度
if($nowpage%$show == 0){
$nowpage =$nowpage - $show + 1;
$end = $nowpage + $show -1;
}else{
$nowpage = floor($nowpage/$show)*10 + 1;
$end = $nowpage + $show -1;
}
$fycod = array();
for($i=$nowpage;$i<=$end;$i++){
$fycod[] = $i;
}
return $fycod;
}
}
分页类代码实现
最新推荐文章于 2021-02-12 10:05:05 发布