我已在以下图片中显示的数据库中保存了逗号分隔的不同功能: 当我选择像这样的单一功能时
SELECT rt.*, rb.*, rf.*, rs.*
FROM business rt
INNER JOIN business_company_info rb
ON rt.id=rb.business_id
INNER JOIN business_attributes rf
ON rt.id=rf.business_id
INNER JOIN business_basic_info rs
ON rt.id=rs.business_id
WHERE business_keyword LIKE '%3000%' AND features LIKE '%feature3%' and
status= 0 ORDER BY rt.id DESC
从数据库中获取数据,但是当我有许多功能时,它无法搜索。 这是我对所选多项功能的查询
SELECT rt.*, rb.*, rf.*, rs.*
FROM business rt
INNER JOIN business_company_info rb
ON rt.id=rb.business_id
INNER JOIN business_attributes rf
ON rt.id=rf.business_id
INNER JOIN business_basic_info rs
ON rt.id=rs.business_id
WHERE business_keyword LIKE '%3000%' AND features LIKE'%feature3,feature2,feature4%' and
status= 0 ORDER BY rt.id DESC
这是我的代码。
if(isset($_POST['advance_search']) && !empty($_POST['advance_search']) && ((isset($_POST['area']) && !empty($_POST['area'])) ||
(isset($_POST['salary']) && !empty($_POST['salary'])) || (isset($_POST['industry']) && !empty($_POST['industry'])) || (isset($_POST['jobtype']) && !empty($_POST['jobtype']))
|| (isset($_POST['keyword']) && !empty($_POST['keyword'])) || (isset($_POST['empnum']) && !empty($_POST['empnum'])) || (isset($_POST['year']) && !empty($_POST['year']))
|| (isset($_POST['features']) && !empty($_POST['features'])) || (isset($_POST['employ_status']) && !empty($_POST['area']))
)){
//echo '<pre>';print_r($_POST);exit;
$area = $_POST['area'];
$salary = $_POST['salary'];
$industry = $_POST['industry'];
$jobtype = $_POST['jobtype'];
$keyword = $_POST['keyword'];
$empnum = $_POST['empnum'];
$year = $_POST['year'];
//echo '<pre>';print_r($ids);print_r($salary);print_r($keyword);print_r($jobtype);print_r($industry);exit;
//echo '<pre>';print_r($area);print_r($salary);print_r($industry);print_r($jobtype);print_r($keyword);print_r($empnum);print_r($year);exit;
/*if(isset($_POST['genre'])){
$genres_search = implode(',', $_POST['genre']);
}*/
if(isset($_POST['employ_status'])){
$employment_search = implode(',', $_POST['employ_status']);
}
if(isset($_POST['features'])){
$features_search = implode(',', $_POST['features']);
}
$conditions = array();
if (!empty($area)){
$conditions[] = "business_location LIKE '%$area%'";
}
if (!empty($salary)){
$conditions[] = "business_salary_rule LIKE '%$salary%'";
}
if (!empty($keyword)){
$conditions[] = "business_keyword LIKE '%$keyword%'";
}
if (!empty($jobtype)){
$conditions[] = "business_job_type >= '$jobtype'";
}
if (!empty($industry)){
$conditions[] = "business_industries LIKE '%$industry%'";
}
if (!empty($empnum)){
$conditions[] = "employees_number LIKE '%$empnum%'";
}
if (!empty($year)){
$conditions[] = "established_year LIKE '%$year%'";
}
if (!empty($employment_search)){
$conditions[] = "employment_status LIKE '%$employment_search%'";
}
if (!empty($features_search)){
$conditions[] = "features LIKE '%$features_search%'";
}
$sql = "SELECT rt.*, rb.*, rf.*, rs.*
FROM business rt
INNER JOIN business_company_info rb
ON rt.id=rb.business_id
INNER JOIN business_attributes rf
ON rt.id=rf.business_id
INNER JOIN business_basic_info rs
ON rt.id=rs.business_id
WHERE ". implode(' AND ', $conditions) . " and
status= 0 ORDER BY rt.id DESC"; echo '<pre>';print_r($sql);exit;
}
任何帮助将不胜感激。谢谢
答案 0 :(得分:2)
如果要查找所有功能的匹配项,则WHERE子句的第一部分应为:
WHERE business_keyword LIKE '%3000%' AND (features LIKE '%feature3%' AND features LIKE '%feature2%' AND features LIKE '%feature4%') .....
如果您想要匹配任何功能,请使用
WHERE business_keyword LIKE '%3000%' AND (features LIKE '%feature3%' OR features LIKE '%feature2%' OR features LIKE '%feature4%') .....
答案 1 :(得分:1)
如果您的数据不是静态的并且正在从数据库中提取,请尝试使用
WHERE business_keyword LIKE'%3000%'AND(功能LIKE'%feature%').....
试试这个。
答案 2 :(得分:1)
您可以展开$功能并将其存储到数组中。 这样的事情。
try {
if (helper != null) {
helper.flagEndAsync();
}
helper.launchPurchaseFlow(.....)
}catch(IllegalStateException e){
e.printStackTrace();
}
希望它有所帮助。