程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> phpZF框架下類似Google搜索分頁

phpZF框架下類似Google搜索分頁

編輯:關於PHP編程

[代碼] [PHP]代碼

view source print? 01 /** 02      * 03      * @param unknown_type $model 表類型 04      * @param unknown_type $ncontroller 那個控制器提交的controller 05      * @param unknown_type $naction 那個action提交的action 06      */ 07     public function fenyepage2($model,$ncontroller,$naction){ 08         if(!isset($_SESSION)) 09         {session_start();} 10         $pageSize $_SESSION['pagesize']; 11         $pageNow $_SESSION['pagenow']; 12         $offset = ($pageNow-1)*$pageSize; 13         $db $this->getAdapter(); 14         $select $db->select(); 15         $select->from('student','*'); 16         if(!isset($_SESSION)) 17         {session_start();} 18         if($_SESSION['qsname']!=""){ 19             $sname $_SESSION['qsname']; 20             $select->where('sname like ?',"%$sname%"); 21         } 22         if($_SESSION['qsaddress']!=""){ 23             $saddress $_SESSION['qsaddress']; 24             $select->where('saddress like ?',"%$saddress%"); 25         } 26         if($_SESSION['qsdept']!=""){ 27             $sdept $_SESSION['qsdept']; 28             $select->where('sdept like ?',"%$sdept%"); 29         } 30         $coutNews $db->fetchAll($select); 31         $pageCount ceil(count($coutNews)/$pageSize); 32         $select->limit($pageSize,$offset);//第一個參數:總共顯示多少個。第二個參數:從第幾個開始顯示 33         $res $db->fetchAll($select); 34         $native = null; 35         $native "<a href='\\$ncontroller\\$naction?pageNow=1&pagesize=$pageSize'>首頁</a>&nbsp"; 36         if($pageNow>1){ 37             $nextPage $pageNow-1; 38             $native.="&nbsp;<a href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>上一頁</a>&nbsp;"; 39         } 40             if(($pageNow-1)>5){ 41                 if($pageNow+4>$pageCount){//如果最後的頁數和理應前面開始的頁數小於10則 42                     $start $pageCount-9;//開始的頁數和結束的頁數相差9 43                 }else{ 44                     $start=$pageNow-5;//開始位置和結束位置相差5 45                 } 46             }else{ 47                 $start floor(($pageNow-1)/10)*10+1; 48             } 49             if($pageCount>=$start+10){ 50                 $index $start+10; 51             } 52             else{ 53                 $index $pageCount+1; 54             } 55   56             for(;$start<$index;$start++){ 57                 $native.="&nbsp;&nbsp;<a href='\\$ncontroller\\$naction?pageNow=$start&pagesize=$pageSize'>$start</a>"; 58             } 59         if($pageNow<$pageCount){ 60             $nextPage $pageNow+1; 61             $native.="&nbsp;&nbsp;<a href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>下一頁</a>&nbsp;";   62         } 63   64         $native.="&nbsp;&nbsp;<a href='\\$ncontroller\\$naction?pageNow=$pageCount&pagesize=$pageSize'>末頁</a>&nbsp;"; 65         $native.="&nbsp;&nbsp;當前{$pageNow}||總共{$pageCount}頁"; 66         $model->arrs = $res; 67         $model->native = $native; 68     }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved