標籤:style blog http color 使用 os strong io
TP內建了一個分頁函數,挺方便使用的。
下面是我的使用方法:
1 /*****************分頁顯示start*************************/ 2 $arr_page=$this->page($user,1); 3 $show=$arr_page[‘show‘]; 4 $Page=$arr_page[‘Page‘]; 5 $article = $user->order(‘now‘)->limit($Page->firstRow.‘,‘.$Page->listRows)->select(); 6 if(!empty($_POST[‘seach_classify‘])){ 7 $seach_classify=$_POST[‘seach_classify‘]; 8 $arr_page=$this->page($user,1,"classify=‘$seach_classify‘"); 9 $show=$arr_page[‘show‘];10 $Page=$arr_page[‘Page‘];11 $Page->setconfig("prev","上");12 13 dump($Page); 14 $article=$user->order("now")->limit($Page->first.‘,‘.$Page->prev)->where("classify=‘$seach_classify‘")->select();15 }16 //dump($list);17 /*****************分頁顯示end************************/
結合自己封裝的一個分頁函數:
public function page($db,$num,$where){ $count = $db->where($where)->count();// $Page = new \Think\Page($count,$num);// 執行個體化分頁類 傳入總記錄數和每頁顯示的記錄數(25) $show = $Page->show();// 分頁顯示輸出 return $arr_page = array( "show"=>$show, "Page"=>$Page, "count"=>$count, ); }
即可實現查詢和按條件查詢分頁,這裡的按條件查詢分頁,雖然能差出資料,但再點擊查詢的分頁連結就返回原來的無條件查詢了,
我這裡判斷的是$_POST[‘seach_classify‘]不為空白才查詢,不過可以理解,如果點擊了查詢分頁連結,頁面會重新整理,$_POST[‘seach_classify‘]就返回是空的了,
現在還想不出解決辦法,望高手解答!
下面是我自訂的分頁效果製作:
需要修改底層的thinkphp/Library/Think/Page.class.php,修改如下:
1 // 分頁顯示定製2 private $config = array(3 ‘header‘ => ‘<span class="rows">共 %TOTAL_ROW% 篇文章</span>‘,//可以直接修改這裡,也可以在你的方法裡面設定$page->setconfig("header","篇文章")4 ‘prev‘ => ‘上一頁‘,//這裡同上5 ‘next‘ => ‘下一頁‘,6 ‘first‘ => ‘返回首頁‘,7 ‘last‘ => ‘...%TOTAL_PAGE%‘,8 ‘theme‘ => ‘%FIRST% %LINK_PAGE% %HEADER% %END%‘,//這裡自訂你的分頁輸出內容,內容在下面9 );
1 //替換分頁內容2 $page_str = str_replace(3 array(‘%HEADER%‘, ‘%NOW_PAGE%‘, ‘%UP_PAGE%‘, ‘%DOWN_PAGE%‘, ‘%FIRST%‘, ‘%LINK_PAGE%‘, ‘%END%‘, ‘%TOTAL_ROW%‘, ),//這裡是自訂所需內容4 array($this->config[‘header‘], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages),5 $this->config[‘theme‘]);6 return "{$page_str}";
下面是效果自訂:
1 //數字串連 2 $link_page = ""; 3 for($i = 1; $i <= $this->rollPage; $i++){ 4 if(($this->nowPage - $now_cool_page) <= 0 ){ 5 $page = $i; 6 }elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){ 7 $page = $this->totalPages - $this->rollPage + $i; 8 }else{ 9 $page = $this->nowPage - $now_cool_page_ceil + $i;10 }11 if($page > 0 && $page != $this->nowPage){12 13 if($page <= $this->totalPages){14 $link_page .= ‘<a class="num" href="‘ . $this->url($page) . ‘"><div>‘ . $page . ‘</div></a>‘;//這裡的div我自己加的,以便用css定製效果!css見下面15 }else{16 break;17 }18 }else{19 if($page > 0 && $this->totalPages != 1){20 $link_page .= ‘<span class="current"><div id="nowPage">‘ . $page . ‘</div></span>‘;21 }22 }23 }
css:
div.fenye{background:; text-align:center; width:800px;margin:15px -400px 0 0; right:50%; position:absolute; box-shadow:0 0 5px #888;}div.fenye div{transition:background 0.5s,box-shadow 1s; text-align:center; width:40px; height:25px; float:left;color:#FFF}div.fenye div:hover{background:#FFF; text-align:center; float:left; color:#000;box-shadow:0 0px 15px #FFF;}div#nowPage{box-shadow:0 0px 15px #FFF;color:#000;background:#FFF;}span.rows{color:#666;};
: