MySQL 数据 - 实现分页的最佳方式?

标签 mysql pagination

我的 iPhone 应用程序连接到我的 PHP Web 服务以从 MySQL 数据库检索数据,一个请求最多可返回 500 个结果。

实现分页并一次检索 20 个项目的最佳方法是什么?

假设我从数据库收到了前 20 个条目,我现在如何请求接下来的 20 个条目?

最佳答案

From the MySQL documentation :

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements).

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15

To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

With one argument, the value specifies the number of rows to return from the beginning of the result set:

SELECT * FROM tbl LIMIT 5;     # Retrieve first 5 rows

In other words, LIMIT row_count is equivalent to LIMIT 0, row_count.

关于MySQL 数据 - 实现分页的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46651646/

相关文章:

Mysql Foreach 循环语法

php - 选择表中所选行的最后插入的 ID

php - 用于检查 MySQL 的 JavaScript 时间戳

php - 解析一串逗号和数字

grails - Grails g:paginate标记和自定义URL

grails - Grails分页:始终显示上一个按钮

php - Codeigniter,使用 WHERE 子句连接两个表

php - 如何在cakephp中使用where子句对连接的多对多表进行分页?

asp.net - 如何使用 asp.net gridview 进行可移动分页?

php - 如何在cakephp的分页中传递参数?