php多条件查询

 

$sql="select *from think_kaoqin WHERE(1=1)";
 
     if(!empty($uid))
            {
                $sql .=" and uid= ".$uid;
            }
             if(!empty($time1) && empty($time2))
            {    
               
                $sql .=" and riqi >= '".$time1."'";
            }
            if (!empty($time2) &&empty($time1)) {
           
                $sql .=" and riqi <= '".$time2."'";
            }
           if (!empty($time1) && !empty($time2)) {
                $sql .=" and riqi >= '".$time1."' and riqi <='".$time2."'";
            }

  $this->info=M('kaoqin')->query($sql);

 

posted @ 2015-09-18 16:33  幻月无痕  阅读(206)  评论(0编辑  收藏  举报