angel1987 Posted May 23, 2010 Share Posted May 23, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/202656-can-anyone-please-explain-me-basic-structure-of-a-simple-forum/ Share on other sites More sharing options...
phant0m Posted May 23, 2010 Share Posted May 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/202656-can-anyone-please-explain-me-basic-structure-of-a-simple-forum/#findComment-1062253 Share on other sites More sharing options...
ignace Posted May 23, 2010 Share Posted May 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/202656-can-anyone-please-explain-me-basic-structure-of-a-simple-forum/#findComment-1062288 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.