1

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

enter image description here

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.

JAL
  • 41,701
  • 23
  • 172
  • 300
  • [This](http://stackoverflow.com/q/14658378/1492578) and [this](http://stackoverflow.com/q/16513418/1492578) may help. – John Bupit Nov 30 '15 at 20:04
  • If you like, consider following this simple two-step course of action: 1. If you have not already done so, provide proper CREATE and INSERT statements (and/or an sqlfiddle) so that we can more easily replicate the problem. 2. If you have not already done so, provide a desired result set that corresponds with the information provided in step 1. – Strawberry Nov 30 '15 at 20:13

2 Answers2

0

Let me do it as PHP array :)

have a look

Fahed Alkaabi
  • 269
  • 2
  • 10
0

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

user3741598
  • 297
  • 1
  • 12
  • I don't think it will work because in the first example the OP means that `3` is `1`s parent and `5` is `3`s parent. – John Bupit Nov 30 '15 at 20:00