美文网首页
php多条件的模糊查询的实现

php多条件的模糊查询的实现

作者: 七百年前 | 来源:发表于2016-08-04 17:33 被阅读353次

1.多条件做的时候有些蒙 不过理清楚了挺简单的

    if ($name) {
        $wherelist[] = "name like '%" .$name. "%'";
       // (id like '%" .$id. "%') or (name like '%" .$name. "%') or (subject like '%" .$subject. "%') 
    }
    if ($mobile) {
        $wherelist[] = "mobile like '%" .$mobile. "%'";
        //$where['mobile'] = $mobile;
    }
    if ($car_code) {
        $wherelist[] = "car_code like '%" .$car_code. "%'";
        //$where['car_code'] = $car_code;
    }
    if ($is_car) {
        $whereand[] = " is_car={$is_car} ";
    }
    
    if ($status) {
        $whereand[] = " status={$status} ";
    }
     //组装查询条件
    if(count($wherelist) > 0){
       $where = implode(' or ' , $wherelist); 
    }

    //组装查询条件
    if(count($whereand) > 0 && $where){
       $aa = implode(' and ' , $whereand); 
       $where = $where.' and '.$aa;
    }elseif(count($whereand) > 0 && !$where){
        $where = implode(' and ' , $whereand);
    }

    //判断查询条件
    $where = isset($where) ? $where : '';

相关文章

网友评论

      本文标题:php多条件的模糊查询的实现

      本文链接:https://www.haomeiwen.com/subject/bvacsttx.html