Encapsulate paging class
Create the page.class.php file to encapsulate the paging class:
##The specific code is as follows:
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2018/3/5 0005 * Time: 下午 5:08 */ class Page{ private $total; //总记录数 private $pagesize;//每页显示的条数 private $current; //当前页 private $pagenum; //总的页数 public function __construct($total,$pagesize,$current) { $this->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='<a href="'.$url.'1">[首页]</a>'; //拼接上一页 $prev=($this->current==1)?'[上一页]':'<a href="'.$url.($this->current-1).'">[上一页]</a>'; //拼接下一页 $next=($this->current==$this->pagenum)?'[下一页]':'<a href="'.$url.($this->current+1).'">[下一页]</a>'; //拼接尾页 $last='<a href="'.$url.$this->pagenum.'">[尾页]</a>'; //组合最终样式 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