谁能帮我弄清楚为什么我在这个查询中得到一个 SQL 错误:
SELECT * FROM articles
LIMIT $offset, $rowsperpage
ORDER BY article_timestamp DESC
非常感谢!
将LIMIT
子句放在查询的末尾。
SELECT * FROM articles
ORDER BY article_timestamp DESC
LIMIT $offset, $rowsperpage
您必须遵循MySQL 的语法..
SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
[ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
[ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name' export_options
| INTO DUMPFILE 'file_name'
| INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]
更多信息:- MySQL SELECT 手册
限制应该结束。它应该先订购然后获得有限的行
SELECT * FROM articles
ORDER BY article_timestamp DESC
LIMIT $offset, $rowsperpage
试试这个:
SELECT *
FROM ARTICLES
ORDER BY ARTICLE_TIMESTAMP DESC
LIMIT $OFFSET, $ROWSPERPAGE