如何使用以下代码搜索多个字段:
if (count($error) < 1) {
$searchSQL = "SELECT sid, sdate, stitle, slocation, skategori, stype, sbody, slist FROM job_search WHERE ";
# grab the search types.
$types = array();
$types[] = isset($_GET['title'])?"`stitle` LIKE '%{$searchTermDB}%'":'';
$types[] = isset($_GET['desc'])?"`skategori` LIKE '%{$searchTermDB}%'":'';
$types[] = isset($_GET['list'])?"`slist` LIKE '%{$searchTermDB}%'":'';
$types = array_filter($types, "removeEmpty");
if (count($types) < 1) {
$types[] = "`sbody` LIKE '%{$searchTermDB}%'";
$andOr = isset($_GET['matchall'])?'AND':'OR';
$searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `stitle`";
$searchResult = mysql_query($searchSQL) or trigger_error("Error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}");
}
}
我在 中使用了一个复选框,$types = array();
如果未选中任何复选框,则搜索将使用$types[] = "sbody LIKE '%{$searchTermDB}%'";
.
我想知道的是如何$types[]
在 中创建多个{$searchTermDB}
并仅使用搜索所有字段 LIKE '%{$searchTermDB}%'";
?