2013-11-28 117 views
-4

這行代碼語法錯誤(MySQL和PHP)

$SQL = "SELECT * FROM stats ORDER BY Team WHERE Team='$teamval'"; 

與下面的MySQL錯誤返回:

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 Team='OTT'' 
at line 1 

我找不到任何錯誤的語法,這有什麼錯它?

+1

[這是從其手冊中有關'SELECT'語句語法]的相關MySQL文檔(http://dev.mysql.com/doc/refman/5.7/ EN/select.html)。 – 2014-05-08 19:43:43

回答

5

ORDER BY條款必須在WHERE條款後出現。因此,您的查詢應該是:

SELECT * FROM stats WHERE Team='$teamval' ORDER BY Team 
1

是您已經在之前WHERE子句,ORDER BY應在查詢結束時使用,如果你已經在你的查詢中使用限用命令的語法是否正確使用,那麼把順序由前限制

SELECT * FROM stats WHERE Team='$teamval' ORDER BY Team 
0

更換:

$SQL="SELECT * FROM stats WHERE Team='$teamval' ORDER BY Team";