Php MySQL Where子句错误

Php MySQL Where子句错误,php,mysql,where-clause,Php,Mysql,Where Clause,我有以下声明 $result = mysql_query("SELECT * from rests ORDER BY name asc WHERE flag = '1' LIMIT 0 , 20"); 我得到以下错误 Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to

我有以下声明

$result = mysql_query("SELECT * from rests ORDER BY name asc WHERE flag = '1' LIMIT 0 , 20");
我得到以下错误

Invalid query: 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 flag = '1' LIMIT 0 , 20' at line 1

我不确定哪里出了问题:(
where
子句之前不能有
orderby
子句

有关各条款的正确顺序,请参阅

试试这个:

SELECT * from rests WHERE flag = '1' ORDER BY name asc LIMIT 0 , 20

此外,默认情况下以升序排序,您可以删除
asc

您不能在
WHERE
子句之前使用
ORDER BY
子句

$result = mysql_query("SELECT * from rests  WHERE flag = '1' ORDER BY name asc LIMIT 0 , 20");
有关各条款的正确顺序,请参阅

试试这个:

SELECT * from rests WHERE flag = '1' ORDER BY name asc LIMIT 0 , 20

另外,默认情况下,您可以删除
asc

中的
排序之前的
中的
排序之前的

子句必须在
WHERE
子句之后。这就是全部。

排序子句必须在
之后在
WHERE
子句后面加上
WHERE
LIMIT
之后加上
ORDER BY
就是这样。

ORDER BY
WHERE
LIMIT
后面加上

$result = mysql_query("SELECT * from rests  WHERE flag = '1' ORDER BY name asc LIMIT 0 , 20");