gpt4 book ai didi

php - MySQL 限制行错误

转载 作者:可可西里 更新时间:2023-11-01 07:49:14 24 4
gpt4 key购买 nike

SELECT * FROM `news` 
WHERE `deleted` = '0'
ORDER BY `time` DESC
LIMIT $START, $END

LIMIT = 0,10 时加载良好。
LIMIT10,20 时,它加载良好。
LIMIT20,30 时,它会再次加载 20,30 中显示的最后 4 行...

最佳答案

您使用 LIMIT 的方式不正确。这不是,

LIMIT <start> <end>

而是,

LIMIT <offset> <number_of_rows>

来自MySQL documentation ,

The first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return.

例如,

... LIMIT 0, 10 -- first 10 rows
... LIMIT 10, 10 -- rows 10-20
... LIMIT 10, 20 -- rows 10-30, not 10-20
... LIMIT 20, 30 -- rows 20-50, not 20-30

如果结果集中没有足够的行来填充限制,它将只返回最后一行。例如,如果您只检索 15 行,...LIMIT 10, 10 将返回第 10-15 行。

关于php - MySQL 限制行错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5799214/

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