Welcome Guest, Not a member yet? Register   Sign In
Forum List
#1

[eluser]Kemik[/eluser]
Hello,

I'm coding a forum using CodeIgniter and trying to work out how to get the results of an sql query in the correct order.

Like most forums, mine will be in the following format...

Category
-> Forum
-> Forum
-> Forum

Category
-> Forum

Etc.

Each forum is held in the forums table. There is a forum_id, parent_id, name, etc. If a forum is a category it will have a parent_id of zero (0). If it is a forum the parent_id is the category's forum_id.

I choose this table structure as it's the same as phpBB3. I believe it's called Modified Preordered Tree Traversal (MPTT). If there's an easier way of storing a basic forum with categories and being able to retrieve them easily, please let me know.

If I pull all the entries in the forums table, how would I order them so that it goes category, then category's forums, next category, then category's forums, etc. I can then use a foreach in the view file to display the forums.

Thanks

Edit: I'm no longer looking for the code as I've found a sitepoint article regarding MPTT. Now I'm just wondering if you think this method over complicates what I'm looking for.




Theme © iAndrew 2016 - Forum software by © MyBB