0

我正在尝试通过 Desending 订购并希望在 Query 中限制 30

PHP代码

$page = $_POST['page'];
$cur_page = $page;
$page -= 1;
$per_page = 30;
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;

$query_pag_data = "SELECT * from titles LIMIT $start, $per_page ORDER BY id DESC";

错误 :MySql ErrorYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id DESC' at line 1

PS:我正在使用分页......所以限制了 30 个这样的结果

4

5 回答 5

3

正确的语法是:

SELECT * from titles 
ORDER BY id DESC
LIMIT $start, $per_page 

LIMIT 在查询的末尾。

于 2013-09-17T06:02:07.090 回答
1

改变位置或LIMITORDER BY,如:

$query_pag_data = "SELECT * from titles ORDER BY id DESC LIMIT $start, $per_page";
于 2013-09-17T06:02:13.057 回答
0

您需要在 LIMIT 之前先放置 ORDER BY 语句

正确的语法如下:

SELECT * FROM *table_name* WHERE *condition* ORBER BY *field_name* LIMIT *limit*;
于 2013-09-17T06:07:16.750 回答
0

LIMIT 语句应始终出现在查询的末尾。

于 2013-09-17T06:45:46.923 回答
0

您必须将限制放在查询的末尾以获得正确的语法:

$query_pag_data = "SELECT * from titles ORDER BY id DESC  LIMIT $start, $per_page";
于 2013-09-17T06:03:03.923 回答