简体   繁体   English

在论坛中查找最后5条帖子

[英]Find last 5 posts in a forum

I have the following table diagramm. 我有下表图表。

One forum can have one or more subforums. 一个论坛可以有一个或多个子论坛。

Example: 例:

id  descr   parentforumid
1   first   0
2   second  0
3   third   1
4   fourth  1
5   fifth   3
6   sixth   2

My aim is when I will get the last posts and set as forumid = 1, that I get all posts from forumid 1 and forumid 3 and forumid 4 and forumid 5. 我的目标是什么时候获得最后的帖子并将其设置为forumid = 1,所以我将获得来自forumid 1和forumid 3以及forumid 4和forumid 5的所有帖子。

And when I search for the forumid = 3, then I should get all posts from forumid 3 and forumid 5 当我搜索forumid = 3时,我应该从forumid 3和forumid 5中获取所有帖子

在此处输入图片说明

I know that I need a recursivly function where I got all the forumid's for searching in the posts, but I have no idea how I starts the solution. 我知道我需要一个递归函数,在该函数中,我可以获取所有Forumid来搜索帖子,但是我不知道如何启动解决方案。

Maybe you have some tipps in which way I have to look or to search. 也许您需要一些寻找或搜索方式的建议。

Let me do it as PHP array :) 让我将其作为PHP数组:)

have a look 看一看

Why won't a simple OR do it? 为什么不简单或做呢? For ex SELECT whatever from table where (id=3 or parentid=3) order by sometimestamp desc limit 5 对于ex SELECT,从表中(id = 3或parentid = 3)排序的东西有时按时间戳记desc限制5

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

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