MySQL/PHP syntax error - looks fine to me
I am doing a fulltext search query in my script and was having trouble. So I added a quick "echo mysql_error" because I was getting false results when I shouldn't have been. Here is the actual typed query:
(*Sending these args respectively: 'announc_threads', 'subject', 'replying'*)
public function searchFulltext ($table, $field, $against) {
$query = "SELECT TID, authorUID, timeStarted,
WHERE MATCH (".$field.") AGAINST ('$against') AS score
开发者_运维知识库 FROM ".$table."
WHERE MATCH (".$field.") AGAINST ('$against')";
Here is the error I'm getting:
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 'WHERE MATCH (subject) AGAINST ('replying') AS score FROM announc_threads WHERE M' at line 1
Looking at the error, everything looks just fine. The biggest problem I have with queries is single/double quotes and using variables (it always seems to change what it wants) - but even those look good, single quotes around the strings, no quotes around table/field names - grrr - do you see anything wrong?
Thanks for any help.
You have a where
in the list of fields, in your select
clause.
I suppose you intend to select the score, and copy-pasted the match...against
stuff from your where
clause, and, that, as a consequence, that where
is probably a copy-paste mistake, and should be removed :
$query = "SELECT TID, authorUID, timeStarted,
MATCH (".$field.") AGAINST ('$against') AS score
FROM ".$table."
WHERE MATCH (".$field.") AGAINST ('$against')";
(The where
I removed was at the begining of the second line of that portion of code)
精彩评论