Jump to content

Recommended Posts

I wil ltry and explain this the best i can so please bare with me if it doesnt come out right first time lol.

 

I am making a forum and as we all know forums have subforums or child boards that are within the forums themselves. Like php freaks has the forum php coding and then a sub forum within it for php regex.

 

Im having trouble coding this though. Anyone have any tips on code and database structure that could help?

I was thinking of making three new database tables for child forums, child topics and child posts but im sure there is an easier way. something like a column within the main forum table which defines wether the forum is a child or not. But then how would i link this child forum with the forum that its supposed to be in. Any advice is greatly appreciated. Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/218793-sub-forums/
Share on other sites

Trying to make it simpler:

 

Basically i could create three extra database tables for child forums, child topics and child posts. But i dont want this. It is alot more work and it can get very confusing. What i want is something like an extra column of two in the forum table. Like child_id and forum type.  Where child id stays at 0 if its not a child and forum type is 'f'. But if it is a child then child id is the id and forum type is 'c'.

 

Then in the code which displays the topics within the forum i need to display all of the topics but i also need to display the child boards within that forum. So something like:

 

 

if ($forum_type == 'c') 
{
loop through the records for all 
child boards with the forum id of the forum
}

 

 

it sounds simple enough but im struggling, especially when i have to work it into my existing code. attached is a copy of topics.php which displays all the topics once someone clicks on a forum.

 

I also added an sql dump of the tables needed to make this page work incase you want to test it.

 

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/218793-sub-forums/#findComment-1134815
Share on other sites

I'm not totally sure  I understand what you're asking.  But I *THINK* I do.  You're having trouble wrapping your head around the idea of tying the children to the parents?

 

You could have ONE table called forums.  Each forum would have a column called parent_id.  If it's a top level forum (it's not a child) then it's parent_id would be 0.  Each forum would have another column simply named ID.

 

Then when defining the children, each one would continue to have unique id numbers in the ID column.  The parent_id column would just list the "id" of it's parent.  Try this:

 

IDNameDescriptionparent_id

1TopLevel1The first of many top level forums0

2TopLevel2The second of many top level forums0

3TopLevel3The Third of many top level forums0

4ChildLevel1-1The first child of the first top level forum1

5ChildLevel1-2The second child of the first top level forum1

6ChildLevel2-1The first child of the Second top level forum2

 

HTH and good luck!

Link to comment
https://forums.phpfreaks.com/topic/218793-sub-forums/#findComment-1134876
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.