我有我的网站上使用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
这些条款是否适用于不同列的名称? – Prix
将你的SQL设置为变量('$ lol =“SELECT ...'),回显变量('echo $ lol;'),然后发送给'mysql_query()'。它是? – DACrosby
不,这是同一列 –