多关键字搜索

时间:2014-07-28 13:22:13

标签: php mysql

我有一个包含逗号分隔关键字的字符串。例如:

$location="Delhi,NOIDA";
$skill="PHP, PHP Programmer";
$cheack2 = "";
$arr=array();
$flag = false;
if(isset($skill) && $skill != "") {

    $query_arr = explode(",", $skill);

    foreach($query_arr as $query_arr2) {
        $arr[] = "job_keyskills like '%$query_arr2%' ";
    }

    $cheack2=implode(" OR ", $arr);
    $flag = true;
}

select * from tb_job where 1=1 and job_keyskills like '%PHP%' OR job_keyskills like '%PHP  Programmer%' OR job_location like '%Delhi%' OR job_location like '%Chhattisgarh%' 

但我想要这种类型的查询

select * from tb_job where 1=1 and job_keyskills like '%PHP%' OR job_keyskills like '%PHP Developer%' AND job_location like '%Delhi%' OR job_location like '%NOIDA%'

1 个答案:

答案 0 :(得分:0)

您的代码中有错误:

if(isset($skill) && $skill != "") {
    if($flag) {
        $cheack2 .= "OR ";
    }
}

你缺少大括号:

select * from tb_job where 1=1 and (job_keyskills like '%PHP%' OR job_keyskills like '%PHP Developer%') AND (job_location like '%Delhi%' OR job_location like '%NOIDA%)