0

降順で注文しようとしていて、クエリで 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

適切な構文を得るには、クエリの最後に制限を設定する必要があります。

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

LIMIT の前に ORDER BY ステートメントを最初に配置する必要があります

正しい構文は次のとおりです。

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