thinkphp條件查詢和模糊查詢的一些方法

來源:互聯網
上載者:User

標籤:des   style   blog   color   os   io   ar   art   

 1     #文章管理 2     public function adminArticle(){ 3         $adminArticle=M("article"); 4         $arr_seach=$this->seach($adminArticle,10,"now desc","");//參數格式seach($db,$num,$order,$where)        5         ##按最早排序 6         if([email protected]empty($_POST[‘time‘])){ 7             $arr_seach=$this->seach($adminArticle,10,"now asc",""); 8         } 9         ##按作者查詢10         if([email protected]empty($_POST[‘author‘])){11             $arr_seach=$this->seach($adminArticle,10,"now asc","author=‘{$_POST[‘author‘]}‘");12         }13         ##按標籤查詢14         if([email protected]empty($_POST[‘classify‘])){15             $arr_seach=$this->seach($adminArticle,10,"now asc","classify=‘{$_POST[‘classify‘]}‘");16         }17         ##模糊查詢18         if([email protected]empty($_POST[‘seach‘])){19             $map[‘title‘] =array(‘like‘,"%{$_POST[‘seach‘]}%",‘or‘);20             $arr_seach=$this->seach($adminArticle,10,"now desc",$map);21         }22         ##輸出到view23         $selectArticle=$arr_seach[‘selectArticle‘];24         $show=$arr_seach[‘show‘];25         $arr_index=array(26             "selectArticle"=>$selectArticle,27             "page"=>$show28             );29         $this->assign($arr_index);30         $this->display();31     }32     ##一個查詢方法33     public function seach($db,$num,$order,$where){34         $count = $db->where($where)->count();// 35         $Page       = new \Think\Page($count,$num);// 執行個體化分頁類 傳入總記錄數和每頁顯示的記錄數(25)36         $show       = $Page->show();// 分頁顯示輸出37 38         $selectArticle=$db->order($order)->where($where)->limit($Page->firstRow.‘,‘.$Page->listRows)->Field(‘id,author,title,classify,now‘)->select();39         40         return $arr_page = array(41         "show"=>$show,42         "selectArticle"=>$selectArticle,43         );44     }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.