3 回答

TA貢獻1829條經驗 獲得超7個贊
您可以使用雙參數形式LIMIT將結果偏移給定的行數,例如:
SELECT *
FROM `mzmx_post`
JOIN mzmx_post_category ON mzmx_post.id = mzmx_post_category.post_id
WHERE mzmx_post_category.category_id = 5
ORDER BY id DESC
LIMIT 2, 2 -- fetch records 3 and 4
這給你第二頁。如果你想要第三頁,那么:
LIMIT 4, 2
等等。
請注意,我修改了您的查詢,因此表之間的連接條件放在ON連接的子句中而不是子句中WHERE。

TA貢獻1863條經驗 獲得超2個贊
基本思想是使用
LIMIT n,o
其中
n 是每頁的結果
o 是第一個結果的偏移量
對于第 p 頁,偏移量為
o = p * n
其中 p = 0,1,2,....

TA貢獻1831條經驗 獲得超10個贊
最好在每個表中添加一個 Long 類型的額外列(例如 mzmx_post_key bigint),并在該列上具有順序值。使用該列從頁面上從數據庫中獲取數據。sql suery 應該是這樣的:
SELECT *
FROM `mzmx_post`
JOIN mzmx_post_category ON mzmx_post.id = mzmx_post_category.post_id
WHERE mzmx_post_category.category_id = 5 and mzmx_post_key> ##last record key##
ORDER BY mzmx_post_key ASC
LIMIT 2
- 3 回答
- 0 關注
- 115 瀏覽
添加回答
舉報