$search_exploded = explode (" ", $search);
foreach($search_exploded as $search_each) {
$x++;
if($x==1)
$construct .="Name LIKE '%$search_each%'";
else
$construct .="AND Name LIKE '%$search_each%'";
}
$construct ="SELECT * FROM Rating, Attraction WHERE $construct" ;
我有列名称,摘要,描述,OpeningHours,地址,邮政编码
我想要做的是触发包含LIKE'%$ search_each%'的'$ construct'查询中的所有这些列
结构是什么,我尝试了OR,AND和UNITE
我已经没有想法了。
答案 0 :(得分:0)
像这样使用concat_ws()
:
$construct ="SELECT * FROM Rating, Attraction WHERE
concat_ws(Name, Summary, Description, OpeningHours, Address, Postcode)
LIKE '%$search_each%'";
希望它有用......
答案 1 :(得分:0)
$columns = array('Name', 'Summary', 'Description', 'OpeningHours', 'Address', 'Postcode')
foreach($columns as $column) {
$search_exploded = explode (" ", $search[$column]);
foreach($search_exploded as $search_each) {
$x++;
if($x==1)
$construct .="$column LIKE '%$search_each%'";
else
$construct .="AND $column LIKE '%$search_each%'";
}
}
您必须记住,$search
现在是一个数组,其搜索条目为每个列键的字符串值。