我的网站上有一个使用 GET 的搜索功能。我一直在尝试编写一些可以从 GET 帖子中取出单词然后使用 SQL 进行搜索的代码。这是我能够做到的:
$id = $_GET["search"];
$searchTerms = explode(' ', $id);
$searchTermBits = array();
foreach ($searchTerms as $term) {
$term = trim($term);
if (!empty($term)) {
$searchTermBits[] = "Name LIKE '%$term%'"
}
}
$lol = mysql_query("SELECT * FROM database WHERE .implode(' AND ', $searchTermBits).")
我不知道我做错了什么。我收到以下错误:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server
version for the right syntax to use near '(' AND ', Array).' at line 1