php通用分頁種

來源:互聯網
上載者:User
php通用分頁類

?

getAllPage()}頁,第{$page->getCurrentPage()}頁 ";$links=$this->getLinkString($param);if($page->hasPrevious())$temp.="getCurrentPage()-1)."'>上一頁 ";else{$temp.="上一頁 ";}for($i=$page->getCurrentPage();$i<=$page->getAllPage()&&$i<=$page->getPerRecords();$i++){$temp.="{$i} ";}if($page->hasNext())$temp.="getCurrentPage()+1)."'>下一頁 ";else{$temp.="下一頁 ";}return $temp;}public function getLinkString($param){$str="";$attr=$_GET;unset($attr[$param]);if($attr){foreach($attr as $key=>$val){if($str==""){$str.="?$key=$val";}else{$str.="&$key=$val";}}$str.="&$param";}else{$str.="?$param";}return $str;}}?>

??

allPage;}/** * @return the $allRecords */public function getAllRecords() {return $this->allRecords;}/** * @return the $perRecords */public function getPerRecords() {return $this->perRecords;}/** * @return the $currentPage */public function getCurrentPage() {return $this->currentPage;}/** * @param $allPage the $allPage to set */public function setAllPage($allPage) {$this->allPage = ($allPage%$this->perRecords == 0)?($allPage/$this->perRecords):($allPage/$this->perRecords+1);$this->allPage=intval($this->allPage);}/** * @param $allRecords the $allRecords to set */public function setAllRecords($allRecords) {$this->allRecords = $allRecords;}/** * @param $perRecords the $perRecords to set */public function setPerRecords($perRecords) {$this->perRecords = $perRecords;}/** * @param $currentPage the $currentPage to set */public function setCurrentPage($currentPage) {if ($currentPage < 1)$this->currentPage = 1;else if ($currentPage > $this->allPage)$this->currentPage =$this->allPage;else$this->currentPage=$currentPage;}public function hasNext() {return $this->currentPage<$this->allPage;}public function hasPrevious() {return $this->currentPage>1;}public function getEndIndex() {return ((($this->currentPage-1)*$this->perRecords)+$this->perRecords)>$this->allRecords?((($this->currentPage-1)*$this->perRecords)+$this->perRecords)-$this->allRecords:$this->perRecords;}public function getStartIndex() {return ($this->currentPage-1)*$this->perRecords;}}?>

?

list=$list;$this->page=new Page();}/** *  * @param unknown_type $rows 顯示的資料量 * @param unknown_type $current 當前頁 */public function init($rows=5,$current){$this->page->setAllRecords(count($this->list));$this->page->setPerRecords($rows);$this->page->setAllPage(count($this->list));$this->page->setCurrentPage($current);$this->list=array_slice($this->list,$this->page->getStartIndex(),$this->page->getEndIndex());}/** * 擷取分頁變數 */public function getVar(){return $this->list;}/** * @return the $param */public function getParam() {return $this->param;}/** * @param $param the $param to set */public function setParam($param) {$this->param = $param;}/** * 載入外掛程式資訊,擷取產生的連結,裝飾器模式 * @param unknown_type $link */public function getLink($link=null){if(!empty($link)||!(($link instanceof ILink)))$link=new LinkAdapter();return $link->parse($this->page,$this->param);}}?>

?

setParam("page");$page->init(30,$_REQUEST['page']);$list=$page->getVar();foreach($list as $val):echo $val.'
';endforeach;echo $page->getLink();?>

?下載

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.