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; //總記錄數(shù) private $pagesize;//每頁顯示的條數(shù) private $current; //當(dāng)前頁 private $pagenum; //總的頁數(shù) 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(){ //計(jì)算limit條件 $lim=($this->current-1)*$this->pagesize; //每頁顯示開始的記錄數(shù) return $lim.','.$this->pagesize; } //獲得url參數(shù),用于在生成分頁鏈接時(shí)保存原有的GET參數(shù) private function getUrlParams(){ //去掉page參數(shù)并重新生成GET參數(shù)字符串 $params=$_GET; unset($params['page']); return http_build_query($params); } //獲取分頁鏈接 public function showPage(){ //如果少于1頁則不顯示分頁導(dǎo)航 if($this->pagenum<=1){ return ''; } //獲取原來的GET參數(shù) $url=$this->getUrlParams(); //拼接URL參數(shù) $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 "當(dāng)前為{$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