php 分页类

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

class Pager

{

var $_total; //记录总数

var $pagesize; //每一页显示的记录数

var $pages; //总页数

var $_cur_page; //当前页码

var $offset; //记录偏移量

var $pernum = 10; //页码偏移量,这里可随意更改

function Pager($total,$pagesize,$_cur_page)

{

$this->_total=$total;

$this->pagesize=$pagesize;

$this->_offset();

$this->_pager();

$this->cur_page($_cur_page);

}

function _pager()//计算总页数

{

return $this->pages = ceil($this->_total/$this->pagesize);

}

function cur_page($_cur_page) //设置页数

{

if (isset($_cur_page)&&$_cur_page!=0)

{

$this->_cur_page=intval($_cur_page);

}

else

{

$this->_cur_page=1; //设置为第一页

}

return $this->_cur_page;

}

//数据库记录偏移量

function _offset()

{

return $this->offset=$this->pagesize*($this->_cur_page-1);

}

//html数字连接的标签

function num_link($tex='?',$url='')

{

$setpage = $this->_cur_page ? ceil($this->_cur_page/$this->pernum) : 1;

$pagenum = ($this->pages > $this->pernum) ? $this->pernum : $this->pages;

if ($this->_total <= $this->pagesize) {

$text = '';

} else {

$text = ''.$this->_cur_page.'/'.$this->pages.' ';

if ($setpage > 1) {

$lastsetid = ($setpage-1)*$this->pernum;

$text .= ' 8 ';

}

if ($this->_cur_page > 1) {

$pre = $this->_cur_page-1;

$text .= '3';

}

$i = ($setpage-1)*$this->pernum;

for($j=$i; $j<($i+$pagenum) && $j<$this->pages; $j++) {

$newpage = $j+1;

if ($this->_cur_page == $j+1) {

$text .= ''.($j+1).'';

} else {

$text .= ''.($j+1).'';

}

}

if ($this->_cur_page < $this->pages){

$next = $this->_cur_page+1;

$text .= '4';

}

if ($setpage < $this->_total) {

$nextpre = $setpage*($this->pernum+1);

if($nextpre<$this->pages)

$text .= '7';

}

}

return $text;

}

//html连接的标签

function link($url, $exc='')

{

global $lang;

$text="

";

$text.= "$lang[pag_total]$this->pages$lang[pags]

$lang[pag_loction]$this->_cur_page$lang[pags] ";

if ($this->_cur_page == 1 && $this->pages>1)

{

//第一页

$text.= "$lang[pag_home] $lang[pag_return] $lang[pag_next] $lang[pag_end]";

}

elseif($this->_cur_page == $this->pages && $this->pages>1)

{

//最后一页

$text.= "$lang[pag_home] $lang[pag_return] $lang[pag_next] $lang[pag_end]";

}

elseif ($this->_cur_page > 1 && $this->_cur_page <= $this->pages)

{

//中间

$text.= "$lang[pag_home] $lang[pag_return] $lang[pag_next] $lang[pag_end]";

}

$text.=" $lang[pag_go]$lang[pags] ";

$text.="

";

return $text;

}

}

相关文档
最新文档