您好,我有一个集成在搜索功能中的选择查询:我有以下代码:
foreach ($keywords as $key=>$keyword){
$where .= "`column_a` LIKE '%$keyword%'";
$where .= " OR ";
$where .= "`column_b` LIKE '%$keyword%'";
$where .= " OR ";
$where .= "`column_c` LIKE '%$keyword%'";
$where .= " OR ";
$where .= "`column_d` LIKE '%$keyword%'";
$where .= " OR ";
$where .= "`column_e` LIKE '%$keyword%'";
if ($key != ($total_keywords - 1)){
$where .= " AND ";
}
}
$results = "SELECT `column_a`, `column_b`, `column_c`, `column_d`, `column_e` FROM `table` WHERE $where";
好的,如果只搜索一个关键字,查询看起来像:
SELECT `column_a`, `column_b`, `column_c`, `column_d`, `column_e` FROM `table` WHERE `column_a` LIKE '%one%' OR `column_b` LIKE '%one%' OR `column_c` LIKE '%one%' OR `column_d` LIKE '%one%' OR `column_e` LIKE '%one%'
什么很长。现在如果有两个搜索词,它看起来像:
SELECT `column_a`, `column_b`, `column_c`, column_d`, `column_e` FROM `table` WHERE `column_a` LIKE '%one%' OR `column_b` LIKE '%one%' OR `column_c` LIKE '%one%' OR `column_d` LIKE '%one%' OR `column_e` LIKE '%one%' AND `column_a` LIKE '%two%' OR `column_b` LIKE '%two%' OR `column_c` LIKE '%two%' OR `column_d` LIKE '%two%' OR `column_e` `LIKE` '%two%'
什么太长了。所以我的问题是,还有其他方法可以获得相同的结果吗?我已经知道有 MATCH() AGAINST() 但这并没有起作用,原因不明。
因此,如果有人可以帮助我,我将不胜感激。多谢。