简体   繁体   中英

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.

And when I search for the forumid = 3, then I should get all posts from forumid 3 and 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.

Maybe you have some tipps in which way I have to look or to search.

Let me do it as PHP array :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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