简体   繁体   English

论坛-上一个活动在多个页面上按顺序排列的主题

[英]Forum - Topics ordered by last activity over multiple pages

I am currently creating a forum with php and sql. 我目前正在用php和sql创建一个论坛。 My problem is how to get the topics into the right order assuming that there are a total of 200 and 15 per Page and I'm on page number 10. 我的问题是,假设每页共有200个和15个,并且我位于第10页上,那么如何使主题按正确的顺序排列。

I can't select per id because if someone posts into one of these topics the timestamp of that specific topic gets updated -> the newest on top. 我无法选择每个ID,因为如果有人将这些主题发布到其中一个主题中,则该特定主题的时间戳将被更新->最新。

For the first page something like that could be okay: 对于第一页,这样可能没问题:

select * from topics order by time desc limit 15 

but for the next page I would need the timestamp of the last topic on the page before. 但对于下一页,我需要之前该页面上最后一个主题的时间戳。

If I could select a specific table by index relative to the timestamp order without the need for the actual index. 如果我可以根据相对于时间戳顺序的索引选择特定的表,而无需实际的索引。

I suggest you check the MySQL documentations for the second argument of the LIMIT clause: 我建议您查看MySQL文档中LIMIT子句的第二个参数:

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) 初始行的偏移量是0(不是1)

Syntax: 句法:

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

Example: 例:

-- page 2:
SELECT * FROM topics ORDER BY time DESC LIMIT 15, 15;
SELECT * FROM topics ORDER BY time DESC LIMIT 15 OFFSET 15;

-- page 3:
SELECT * FROM topics ORDER BY time DESC LIMIT 30, 15;
SELECT * FROM topics ORDER BY time DESC LIMIT 15 OFFSET 30;

-- page n:
SELECT * FROM topics ORDER BY time DESC LIMIT (n-1)*15, 15;
SELECT * FROM topics ORDER BY time DESC LIMIT 15 OFFSET (n-1)*15;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM