码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp条件查询和模糊查询的一些方法

时间:2014-08-15 14:31:18      阅读:356      评论:0      收藏:0      [点我收藏+]

标签: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(!@empty($_POST[‘time‘])){
 7             $arr_seach=$this->seach($adminArticle,10,"now asc","");
 8         }
 9         ##按作者查询
10         if(!@empty($_POST[‘author‘])){
11             $arr_seach=$this->seach($adminArticle,10,"now asc","author=‘{$_POST[‘author‘]}‘");
12         }
13         ##按标签查询
14         if(!@empty($_POST[‘classify‘])){
15             $arr_seach=$this->seach($adminArticle,10,"now asc","classify=‘{$_POST[‘classify‘]}‘");
16         }
17         ##模糊查询
18         if(!@empty($_POST[‘seach‘])){
19             $map[‘title‘] =array(‘like‘,"%{$_POST[‘seach‘]}%",‘or‘);
20             $arr_seach=$this->seach($adminArticle,10,"now desc",$map);
21         }
22         ##输出到view
23         $selectArticle=$arr_seach[‘selectArticle‘];
24         $show=$arr_seach[‘show‘];
25         $arr_index=array(
26             "selectArticle"=>$selectArticle,
27             "page"=>$show
28             );
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     }

 

thinkphp条件查询和模糊查询的一些方法,布布扣,bubuko.com

thinkphp条件查询和模糊查询的一些方法

标签:des   style   blog   color   os   io   ar   art   

原文地址:http://www.cnblogs.com/mrcln/p/3914709.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!