时间:2021-07-01 10:21:17 帮助过:29人阅读
class page{ private $_page_num;//总页数 private $_page_size=10;//每页条数 private $_page_url;//url链接 private $_limit;//limit1 private $_page_total;//总分页数 private $_page;//分页所传分页值 private $_list_size=10;//这为第二种分页方法显示条数 private $_page_sort=3;//分页两边距离 public function __construct($_total,$_pagesize,$_list_size){ $this->_page_size=$_pagesize; $this->_page_total=$_total; $this->_list_size = $_list_size; $this->_page_num = round($this->_page_total/$this->_page_size); $this->_page=$this->getnum(); $this->_limit="limit".$this->_page*$this->_page_size.",".$this->_page_total=$_total; $this->_page_url=$this->seturl(); } /** * 获取当前页数 * Enter description here ... */ private function getnum(){ if(isset($_GET['page'])){ if(is_numeric($_GET['page'])){ if($_GET['page']>0){ if(ceil($_GET['page'])>=1 && ceil($_GET['page'])<=$this->_page_num){ return ceil($_GET['page']); }elseif(ceil($_GET['page'])>$this->_page_num){ return $this->_page_num; } }else{ return 1; } }else{ return 1; } }else{ return 1; } } /** * 转换链接 * Enter description here ... */ private function seturl(){ $_url=$_SERVER['REQUEST_URI'];//获取请求地址 $_par=parse_url($_url);//解析url if(isset($_par['query'])){//判断是否存在aa=bb这种格式 $_url=parse_str($_par['query'],$_query);//重构url unset($_query['page']); $_url=$_par['path'].'?'.http_build_query($_query); }else{ $_url=$_url.'?'; } return $_url; } public function limit(){ return $this->_limit; } public function pagenum(){ return $this->_page_num; } /* public function page(){ return $this->_page; } public function pageurl(){ return $this->_page_url; } */ private function first(){ return "_page_url."&page=1>首页"; } private function end(){ return "_page_url."&page=".$this->_page_num.">尾页"; } private function prev(){ if($this->_page>1){ return "_page_url."&page=".($this->_page-1).">上一页"; }else{ return '上一页'; } } public function next(){ if($this->_page<$this->_page_num){ return "_page_url."&page=".($this->_page+1).">下一页"; }else{ return '下一页'; } } private function pagelist_1(){ $_page=''; for($i=1;$i<=$this->_page_num;$i++){ $_page.="_page_url."&page=".$i.">".$i.""; } return $_page; } private function pagelist_2(){ $_page=''; $_page_start=floor($this->_page/$this->_list_size); $usenum=$this->check(($_page_start*$this->_list_size+10),$this->_page_num); for($i=$_page_start*$this->_list_size+1;$i<=$usenum;$i++){ $_page.="_page_url."&page=".$i.">".$i.""; } return $_page; } private function pagelist_3(){ $page=''; for($i=$this->_page-$this->_page_sort;$i<=$this->_page-1;$i++){ if($i<1)continue; $page.="_page_url."&page=".$i.">".$i."".' '; } $page.="_page_url."&page=".$this->_page.">".$this->_page."".' '; for($i=$this->_page+1;$i<=$this->_page+$this->_page_sort;$i++){ if($i>$this->_page_num)break; $page.="_page_url."&page=".$i.">".$i."".' '; } return $page; } /** * 没有修正的分页列表 * Enter description here ... */ private function pagelist_4(){ $page=''; for($i=$this->_page-$this->_page_sort;$i<=$this->_page-1;$i++){ if($i<1)continue; $page.="_page_url."&page=".$i.">".$i."".' '; } $page.="_page_url."&page=".$this->_page.">".$this->_page."".' '; for($i=$this->_page+1;$i<=$this->_page+$this->_page_sort;$i++){ if($i>$this->_page_num)break; $page.="_page_url."&page=".$i.">".$i."".' '; } //+1和-1为了排除上一页显示的值,不然会重复 if($this->_page>($this->_page_sort+1) && $this->_page<($this->_page_num-$this->_page_sort)){ $page="_page_url."&page=".($this->_page-$this->_page_sort*2-1).">...".$page."_page_url."&page=".($this->_page+$this->_page_sort*2+1).">..."; } return $page; } private function check($num1,$num2){ if($num1>$num2){ return $num2; }else{ return $num1; } } public function showpage($_type){ $_page=''; $_page.=$this->first();//首页 switch($_type){ case '1': $_page.=$this->pagelist_1();//原始页面列表 break; case '2': $_page.=$this->pagelist_2();//原始页面列表 break; case '3': $_page.=$this->pagelist_3();//原始页面列表 break; case '4': $_page.=$this->pagelist_4();//原始页面列表 break; default: $_page.=$this->pagelist_3();//默认原始页面列表 } $_page.=$this->end();//尾页 $_page.=$this->prev();//上一页 $_page.=$this->next();//下一页 return $_page; }}// $page = new page(220,10,10);// echo $page->showpage('4');
不好意思,我是初学者,对类不太会用,现在是点击(如家电)后显示以下内容:
当前位置 | 首页 | 家电类
内容1
内容2
内容3
共 2页 第 1页 共 5 条记录 下一页 尾页
点下一页只显示:
当前位置 | 首页 | 类
共 8页 第 2页 共 30 条记录 首页上一页 下一页 尾页
虽然不太懂,但我找到其他方法了