Jump to content

Can anyone please explain me basic structure of a simple forum?


angel1987

Recommended Posts

I am new to PHP but i have started very well and managed to create an article submission kind working website, not completely but i think i can do good database driven script but now i am thinking of creating a simple forum and as i think about how to do it, with every thought it takes me to like never ending number of steps.

 

So how does forums work anyway, is there a new table created for each new topic started ? because a new topic will have many replies.

 

Also first there will be a table for listing of Main Board Category and then one table for its Sub Boards and then users will create New topics in these sub boards where they will get replies right?

 

That is what i have in mind, so any thought or help from you?

Link to comment
Share on other sites

You should never change the database structure depending on the data to store. It means that your database layout is not good.

 

You just store the posts in a table, and have an other table for topics. You just store an topic_id for each post, so you know where it belongs. As for categories: you can use a simple tree layout with an id and a parent_id. It's not very effective but very simple to implement.

 

Read about database normalization.

Link to comment
Share on other sites

Something like:

 

CREATE TABLE forum (
  id smallint NOT NULL AUTO_INCREMENT,
  parent_id smallint,
  ..
  
  INDEX forum_parent_id_FK (parent_id),
  FOREIGN KEY forum_parent_id_FK (parent_id) REFERENCES forum (id)
    ON UPDATE NO ACTION ON DELETE NO ACTION,
  PRIMARY KEY (id)
) ENGINE = InnoDB;

CREATE TABLE forum_reply (
  id integer NOT NULL AUTO_INCREMENT,
  replyto_id integer NOT NULL,
  forum_id smallint NOT NULL,
  ..
  
  INDEX forum_reply_replyto_id_FK (replyto_id),
  FOREIGN KEY forum_reply_replyto_id_FK (replyto_id) REFERENCES forum_reply (id)
    ON UPDATE NO ACTION ON DELETE NO ACTION,
  
  INDEX forum_reply_forum_id_FK (forum_id),
  FOREIGN KEY forum_reply_forum_id_FK (forum_id) REFERENCES forum (id)
    ON UPDATE NO ACTION ON DELETE NO ACTION,
  
  PRIMARY KEY (id)
) ENGINE = InnoDB;

 

You would create a forum and add sub-forums by specifying the forum.parent_id. When someone creates a thread you would specify to which a user replies by using forum_reply.replyto_id.

Link to comment
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.