您好,登錄后才能下訂單哦!
<?php //自定義分頁類 class Page { public $page=1; //當前頁 public $pageSize=5; //頁大小 public $maxPage=0; //最大頁數 public $maxRows=0; //最大數據條 public $url =null; //訪問的url地址 public $params=null; //url的參數條件 public function __construct($maxRows,$pageSize=5){ $this->maxRows = $maxRows; $this->pageSize= $pageSize; //獲取當前頁 $this->page = isset($_GET['p'])?$_GET['p']:1; $this->getMaxPage(); $this->checkPage(); //獲取和封裝url地址 $this->url = $_SERVER["PHP_SELF"]; $this->getParams(); } //獲取分頁信息 public function limit(){ return (($this->page-1)*$this->pageSize).",".$this->pageSize; } //計算分頁中的最大頁數 private function getMaxPage(){ $this->maxPage = ceil($this->maxRows/$this->pageSize); } //判斷當前頁數是否越界 private function checkPage(){ if($this->page>$this->maxPage){ $this->page = $this->maxPage; } if($this->page<1){ $this->page=1; } } //封裝url上搜索條件 private function getParams(){ foreach($_GET as $k=>$v){ if($k!="p" && !empty($v)){ $this->params.="&{$k}={$v}"; } } } //生成分頁HTML代碼 public function show(){ $str = ""; $str.= "當前第{$this->page}/{$this->maxPage}頁 共計{$this->maxRows}條 "; $str.= " <a href='{$this->url}?p=1{$this->params}'>首頁</a> "; $str.= " <a href='{$this->url}?p=".($this->page-1)."{$this->params}'>上一頁</a> "; $str.= " <a href='{$this->url}?p=".($this->page+1)."{$this->params}'>下一頁</a> "; $str.= " <a href='{$this->url}?p={$this->maxPage}{$this->params}'>末頁</a> "; return $str; } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。