PHP封装的完整分页类示例

前端之家收集整理的这篇文章主要介绍了PHP封装的完整分页类示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP封装的完整分页类。分享给大家供大家参考,具体如下:

PHP;"> total = $_total ? $_total :1 ; //总条数 $this->pagesize = $_pagesize; //每页显示多少条 $this->page = $page; //当前页码 $this->pagenum = ceil($this->total / $this->pagesize); //总页码 $this->limit = "limit ".($this->page-1)*$this->pagesize.",".$this->pagesize; //分页语句 $this->url = $this->setUrl(); //地址 } //分页语句 public function limit(){ return $this->limit; } //当前的URL地址 public function setUrl(){ $server = $_SERVER['REQUEST_URI']; $im = explode('/',$server); if(empty($_SERVER['PATH_INFO'])){ $array = array_splice($im,2,array('2'=>'index.PHP')); } $controller = $im[3]; $action = $im[4]; if(empty($_SERVER['PATH_INFO'])){ $servers = "http://".$_SERVER['HTTP_HOST']."/".$im[1]."/".$controller."/".$action."/"; }else{ $servers = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."/".$controller."/".$action."/"; } return $servers; //return $im; } //首页 public function first(){ //return $this->page; if($this->page > 1){ return "首页"; } } //上一页 public function prev(){ if($this->page==1){ $page = 1; }else{ $page = $this->page-1; } if($this->page > 1){ return "上一页"; }else{ return "上一页"; } } //下一页 public function next(){ $page = $this->page+1; if($this->page < $this->pagenum){ if(empty($this->page)){ $pages = $this->page+2; return "下一页"; }else{ return "下一页"; } }else{ return "下一页"; } } //尾页 public function last(){ if($this->page < $this->pagenum){ return "尾页"; } } //分页 public function showpage(){ $page_ = ""; $page_ .= $this->first(); $page_ .= " ".$this->prev(); $page_ .= " ".$this->next(); $page_ .= " ".$this->last(); return $page_; } }

更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《PHP常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

猜你在找的PHP相关文章