gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 18:20:14 25 4
gpt4 key购买 nike

我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com