欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

大神帮小弟我看下,小弟我的查询分页类错哪了分页类

程序员文章站 2022-04-05 15:49:28
...
大神帮我看下,我的查询分页类哪里错了分页类

这是page.class.php
class DividePage{//分页类
private $total;//要显示的总记录数
private $url;//请求的URL地址
private $displaypg;//每页显示的记录数,默认为每页显示10条记录
private $page;//当前页码
private $lastpg;//总页数,即最后一页的页码
private $prepg;//前一页
private $nextpg;//后一页
private $firstcount;//记录条数开始的序号从0开始
private $startd;//记录条数开始的记录号.
private $stopd;//记录条数结束的记录号.

//构造函数
public function __construct($url, $total, $displaypg){
$this->url = $url;//请求的URL
$this->total = $total;//总记录数
//if($displaypg == '')
$this->displaypg = $displaypg;//每页显示的记录数
$this->initDividePage();//初始化分页类
//echo ','.$this->displaypg;
}

//初始化分页类
private function initDividePage(){
//分析URL
$parse_url = parse_url($this->url);//将URL解释为有固定键值对的数组
$url_query = $parse_url['query'];//取出URL中的查询字符串
if($url_query){//如果有查询字符串,则删除查询字串中当前页的查询字段如:&page=$page或page=$page
ereg('(^|&)page=([0-9]*)', $url_query, $k);
$this->page = $k[2];//取得当前页的值
$url_query = ereg_replace("(^|&)page=$this->page", '', $url_query);//删除查询字串中当前页的查询字段如:&page=$page或page=$page
$this->url = str_replace($parse_url['query'], $url_query, $this->url);//保留其他的查询字串,
$this->page = $this->page ? $this->page : 1;//如果查询字符串中没有当前页的值就设当前页为1
if($url_query){//如果有其他查询字符串,则以&page=$page形式添加翻页查询字串
$this->url .= '&page';
}else{//如果没有其他查询字串,则以page=$page形式添加翻页查询字串
$this->url .= 'page';
}
}else{//如果没有查询字串,则在URL后添加?page=$page形式的翻页查询字串
$this->page = 1;
$this->url .= '?page';
}
$this->lastpg = ceil($this->total / $this->displaypg);//计算总页数,即最后一页的页码
$this->page = min($this->lastpg, $this->page);//如果当前页大于总页数,则当前页为最后一页的页码
$this->prepg = $this->page - 1;//上一页为当前页减一
$this->nextpg = $this->page + 1;//(($this->page == $this->lastpg) ? $this->lastpg : ($this->page + 1));//下一页为当前页加一,如果当前页为最后一页,则下一页为0
$this->firstcount = ($this->page - 1) * $this->displaypg;//计算当前页,记录条数开始的记录号,从0开始.
$this->startd = $this->total ? ($this->firstcount + 1) : 0;//记录开始号从1开始
$this->stopd = min($this->firstcount + $this->displaypg, $this->total);//记录结束号
//echo $this->displaypg;
//echo $this->nextpg.'+=+='.$this->lastpg;
}

public function getPageInfo(){//取得当前页面的基本信息,如:显示第 1-10 条记录,共 23 条记录。
return '显示第'.$this->startd.'-'.$this->stopd.'条记录,共'.$this->total.'条记录。';
}

public function getCommonPageNav(){//取得通常的分页导航,如:首页 上一页 下一页 尾页
$commonnav = '';
if($this->lastpg == 1){//如果只有一页,则返回翻页导航,退出,不显示下一页,上一页等。。。
return $commonnav;
break;
}
$commonnav = '首页';//设置首页导航,page=1
if($this->prepg){
$commonnav .= '上一页';
}else{
大神帮小弟我看下,小弟我的查询分页类错哪了分页类

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频