php多条件のファジイクエリの実装
1226 ワード
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 : '';