Home > Article > Backend Development > 大神帮小弟我看下,小弟我的查询分页类错哪了分页类
大神帮我看下,我的查询分页类哪里错了分页类
<br>这是page.class.php<br><?php <br />class DividePage{//分页类<br> private $total;//要显示的总记录数<br> private $url;//请求的URL地址<br> private $displaypg;//每页显示的记录数,默认为每页显示10条记录<br> private $page;//当前页码<br> private $lastpg;//总页数,即最后一页的页码<br> private $prepg;//前一页<br> private $nextpg;//后一页<br> private $firstcount;//记录条数开始的序号从0开始<br> private $startd;//记录条数开始的记录号.<br> private $stopd;//记录条数结束的记录号.<br><br>//构造函数<br>public function __construct($url, $total, $displaypg){<br> $this->url = $url;//请求的URL<br> $this->total = $total;//总记录数<br> //if($displaypg == '')<br> $this->displaypg = $displaypg;//每页显示的记录数<br> $this->initDividePage();//初始化分页类<br> //echo ','.$this->displaypg;<br>}<br><br>//初始化分页类<br>private function initDividePage(){<br> //分析URL<br> $parse_url = parse_url($this->url);//将URL解释为有固定键值对的数组<br> $url_query = $parse_url['query'];//取出URL中的查询字符串<br> if($url_query){//如果有查询字符串,则删除查询字串中当前页的查询字段如:&page=$page或page=$page<br> ereg('(^|&)page=([0-9]*)', $url_query, $k);<br> $this->page = $k[2];//取得当前页的值<br> $url_query = ereg_replace("(^|&)page=$this->page", '', $url_query);//删除查询字串中当前页的查询字段如:&page=$page或page=$page<br> $this->url = str_replace($parse_url['query'], $url_query, $this->url);//保留其他的查询字串,<br> $this->page = $this->page ? $this->page : 1;//如果查询字符串中没有当前页的值就设当前页为1<br> if($url_query){//如果有其他查询字符串,则以&page=$page形式添加翻页查询字串<br> $this->url .= '&page';<br> }else{//如果没有其他查询字串,则以page=$page形式添加翻页查询字串<br> $this->url .= 'page';<br> }<br> }else{//如果没有查询字串,则在URL后添加?page=$page形式的翻页查询字串<br> $this->page = 1;<br> $this->url .= '?page';<br> }<br> $this->lastpg = ceil($this->total / $this->displaypg);//计算总页数,即最后一页的页码<br> $this->page = min($this->lastpg, $this->page);//如果当前页大于总页数,则当前页为最后一页的页码<br> $this->prepg = $this->page - 1;//上一页为当前页减一<br> $this->nextpg = $this->page + 1;//(($this->page == $this->lastpg) ? $this->lastpg : ($this->page + 1));//下一页为当前页加一,如果当前页为最后一页,则下一页为0<br> $this->firstcount = ($this->page - 1) * $this->displaypg;//计算当前页,记录条数开始的记录号,从0开始.<br> $this->startd = $this->total ? ($this->firstcount + 1) : 0;//记录开始号从1开始<br> $this->stopd = min($this->firstcount + $this->displaypg, $this->total);//记录结束号<br> //echo $this->displaypg;<br> //echo $this->nextpg.'+=+='.$this->lastpg;<br>}<br><br>public function getPageInfo(){//取得当前页面的基本信息,如:显示第 1-10 条记录,共 23 条记录。<br> return '<span>显示第<span>'.$this->startd.'-'.$this->stopd.'</span>条记录,共<span>'.$this->total.'</span>条记录。</span>';<br>}<br><br>public function getCommonPageNav(){//取得通常的分页导航,如:首页 上一页 下一页 尾页<br> $commonnav = '';<br> if($this->lastpg == 1){//如果只有一页,则返回翻页导航,退出,不显示下一页,上一页等。。。<br> return $commonnav;<br> break;<br> }<br> $commonnav = '<a>url.'=1" class="compagestyle">首页</a>';//设置首页导航,page=1<br> if($this->prepg){<br> $commonnav .= '<a>url.'='.$this->prepg.'" class="compagestyle">上一页</a>';<br> }else{<div class="clear"> </div>