zoukankan      html  css  js  c++  java
  • thinkphp条件查询和模糊查询的一些方法

     1 #文章管理
     2     public function adminArticle(){
     3         $adminArticle=M("article");
     4         $arr_seach=$this->seach($adminArticle,10,"篇文章","now desc","");//参数格式seach($db,$num,$page_header,$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 desc","author='{$_POST['author']}'");
    12         }
    13         ##按标签查询
    14         if(!@empty($_POST['classify'])){
    15             $arr_seach=$this->seach($adminArticle,10,"篇文章","now desc","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,$page_header,$order,$where){
    34         $count = $db->where($where)->count();// 
    35         $Page       = new ThinkPage($count,$num);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    36         if($page_header==false){
    37             $Page->setConfig("header","");
    38         }else{
    39             $Page->setConfig("header","<span class='rows'>共 %TOTAL_ROW% ".$page_header."</span>");
    40         }
    41         $show       = $Page->show();// 分页显示输出
    42 
    43         $selectArticle=$db->order($order)->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();
    44         
    45         return $arr_page = array(
    46         "show"=>$show,
    47         "Page"=>$Page,
    48         "selectArticle"=>$selectArticle,
    49         );
    50     }
  • 相关阅读:
    UVA 11384 Help is needed for Dexter(问题转化 递归)
    UVA 11991 Easy Problem from Rujia Liu?(vector map)
    poj 2656 Unhappy Jinjin
    解析磁盘0号扇区数据
    树的非递归遍历
    iOS项目开发实战——使用同步请求获取网页源码
    单点登录cas常见问题(四)
    bzoj2115【WC2001】Xor
    最小化JavaScript代码
    quick-cocos2d-x教程9:实例之加上背景图片
  • 原文地址:https://www.cnblogs.com/mrcln/p/3914709.html
Copyright © 2011-2022 走看看