本文實例講述了Zend Framework框架實現類似Google搜索分頁效果。分享給大家供大家參考,具體如下:
/** * * @param unknown_type $model 表類型 * @param unknown_type $ncontroller 那個控制器提交的controller * @param unknown_type $naction 那個action提交的action */ public function fenyepage2($model,$ncontroller,$naction){ if(!isset($_SESSION)) {session_start();} $pageSize = $_SESSION['pagesize']; $pageNow = $_SESSION['pagenow']; $offset = ($pageNow-1)*$pageSize; $db = $this->getAdapter(); $select = $db->select(); $select->from('student','*'); if(!isset($_SESSION)) {session_start();} if($_SESSION['qsname']!=""){ $sname = $_SESSION['qsname']; $select->where('sname like ?',"%$sname%"); } if($_SESSION['qsaddress']!=""){ $saddress = $_SESSION['qsaddress']; $select->where('saddress like ?',"%$saddress%"); } if($_SESSION['qsdept']!=""){ $sdept = $_SESSION['qsdept']; $select->where('sdept like ?',"%$sdept%"); } $coutNews = $db->fetchAll($select); $pageCount = ceil(count($coutNews)/$pageSize); $select->limit($pageSize,$offset);//第一個參數:總共顯示多少個。第二個參數:從第幾個開始顯示 $res = $db->fetchAll($select); $native = null; $native = "<a href='\\$ncontroller\\$naction?pageNow=1&pagesize=$pageSize'>首頁</a> "; if($pageNow>1){ $nextPage = $pageNow-1; $native.=" <a href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>上一頁</a> "; } if(($pageNow-1)>5){ if($pageNow+4>$pageCount){//如果最後的頁數和理應前面開始的頁數小於10則 $start = $pageCount-9;//開始的頁數和結束的頁數相差9 }else{ $start=$pageNow-5;//開始位置和結束位置相差5 } }else{ $start = floor(($pageNow-1)/10)*10+1; } if($pageCount>=$start+10){ $index = $start+10; } else{ $index = $pageCount+1; } for(;$start<$index;$start++){ $native.=" <a href='\\$ncontroller\\$naction?pageNow=$start&pagesize=$pageSize'>$start</a>"; } if($pageNow<$pageCount){ $nextPage = $pageNow+1; $native.=" <a href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>下一頁</a> "; } $native.=" <a href='\\$ncontroller\\$naction?pageNow=$pageCount&pagesize=$pageSize'>末頁</a> "; $native.=" 當前{$pageNow}||總共{$pageCount}頁"; $model->arrs = $res; $model->native = $native; }
更多關於zend相關內容感興趣的讀者可查看本站專題:《Zend FrameWork框架入門教程》、《php優秀開發框架總結》、《Yii框架入門及常用技巧總結》、《ThinkPHP入門教程》、《php面向對象程序設計入門教程》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
希望本文所述對大家基於Zend Framework框架的PHP程序設計有所幫助。