Encapsulate paging class

Create the page.class.php file to encapsulate the paging class:

##The specific code is as follows:

total=$total; $this->pagesize=$pagesize; $this->current=$current; $this->pagenum=ceil($this->total/$this->pagesize); } //获取SQL中的limit条件 public function getLimit(){ //计算limit条件 $lim=($this->current-1)*$this->pagesize; //每页显示开始的记录数 return $lim.','.$this->pagesize; } //获得url参数,用于在生成分页链接时保存原有的GET参数 private function getUrlParams(){ //去掉page参数并重新生成GET参数字符串 $params=$_GET; unset($params['page']); return http_build_query($params); } //获取分页链接 public function showPage(){ //如果少于1页则不显示分页导航 if($this->pagenum<=1){ return ''; } //获取原来的GET参数 $url=$this->getUrlParams(); //拼接URL参数 $url=$url?"?$url&page=":"?page="; //拼接"首页" $first='[首页]'; //拼接上一页 $prev=($this->current==1)?'[上一页]':'[上一页]'; //拼接下一页 $next=($this->current==$this->pagenum)?'[下一页]':'[下一页]'; //拼接尾页 $last='[尾页]'; //组合最终样式 return "当前为{$this->current}/{$this->pagenum} {$first} {$prev} {$next} {$last}"; } }

1, you need to know what basic attributes are required for paging

private $total; //The total number of records (obtained by querying the database)

private $pagesize;//The number of items displayed on each page (according to your own Need to be set)
private $current; //The current page (the default is the first page, each time you click the next page, it will add 1)
private $pagenum; //The total number of pages (through the total number of records/ The number of items displayed on each page is rounded up or calculated by (total number of records - 1/number of items displayed on each page) 1) to get

2. The display page is as follows:

微信图片_20180306143845.png


Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!