欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

多字段查询,多条件查询写法

程序员文章站 2024-03-05 15:44:01
...
    /**
     * 查询展示信息
     * 
     */
public function order(){
$data=I();
$uid=$_SESSION['id'];
//print_r($_SESSION);
if($uid==1){
  $where=array();
}elseif($uid==2){
  $where=array();
}elseif($uid==3){
  $where=array();
}else{
  $where=array('uid'=>$uid);
}

//print_r($data);
$starttime=$data['starttime'];
$endtime=$data['endtime'];
$states=$data['states'];
$searcher=$data['searcher'];

if(!empty($starttime)){
    //$this->timebegin = $starttime;
    //$this->bbs_forums->_serarch_type['dotimeBegin'] = $dotimeBegin; 
    //$map['id']  = array('elt',100);
    $where['calltime']= array('egt',$starttime);
}
if(!empty($endtime)){
    //$this->timeend = $endtime;
    //$this->bbs_forums->_serarch_type['dotimeBegin'] = $dotimeBegin; 
    $where['calltime']= array($where['calltime'],array('elt',$endtime));
}
//print_r($where);exit;
if(!empty($states)){
    //$this->gostates = $states;
    //$this->bbs_forums->_serarch_type['dotimeBegin'] = $dotimeBegin; 
    $where['states']=$states;
}
if(!empty($searcher)){
    //$this->gosearcher =$searcher;
    //$this->bbs_forums->_serarch_type['dotimeBegin'] = $dotimeBegin;
    //$where['customuser']=array('like',"%{$searcher}%");
    //$where['tel']=array('like',"%{$searcher}%");
    $where['_string'] ="(customuser like '%{$searcher}%') OR (tel like '%{$searcher}%') ";
}

//print_r($where);exit;
 $obj=M();
$total=$obj->table("custom")->where($where)->count();
$page=new \Think\Page($total,12,$parameter);
$page->setconfig("prev","上一页"); 
$page->setconfig("next","下一页"); 
$arr=$obj->table("custom")->where($where)->order("calltime desc")->limit($page->firstRow,$page->listRows)->select();
$show=$page->show();
//echo $obj->getLastSql(); 
//print_r($arr);
//exit;
$prarr=$obj->table("province")->select();
$cityarr=$obj->table("city")->select();
$areaarr=$obj->table("area")->select();
$this->assign("uid",$uid)->assign("show",$show)->assign("prarr",$prarr)->assign("cityarr",$cityarr)->assign("areaarr",$areaarr)->assign("arr",$arr)->display();
}
相关标签: 多条件查询设计