I have just jumped head first into PHP this month, and am loving every minute of it. I would like to create a MySQL database forum using php, but I am unsure how to structure it:

Should I create a new table in my 'forum' database for every new topic? This would mean that each row in the table would be a thread within that parent topic (table).

Is this a bad way of managing a forum, or does php allow for a more practical way? I am unsure of the downsides to having a massive amount of tables in a database. Bare with me, I'm a total rookie! Any help is much appreciated.

Devin

    Might be a good idea to think smaller for your first project. Forums are not as simple as they first appear.

      Well if it was me I definately wouldn't create a new table for every topic, I would put all my posts in 1 table, and then have a table called topics with fields 'topic_id' & 'topic_name', then in your posts table a 'post' can have a 'topic_id' associated with it.

      this way your posts are in 1 place, if the posts table gets too full (i.e. you've got a few million records in there) then just archive away the old posts from the db.

      hope this helps a bit...

        Yes, I understand this is more of a task than it seems, but I need a place to start. I have been running all sorts of databas scripts since I started, and I want to at least have an idea of how I should manage it.

        Thanks for the advice, that makes a lot more sense. I'll definately take that approach to start. Thanks again!

        Devin

          In it's very simplest form a single forum only needs one table.

          posts
          --------
          [u]post_id[/u]
          parent_id
          title
          body
          author
          

          With this design you have a deeper tree like structure (like that on /.). Each post either has a parent or is a root post ie the begining of a thread. To build up around from this one table is then pretty simple. Add a user_id element and create a users table; add forum_id element and a forums table; add status element for things like sticky; and you can add a locked element to say if a post is locked. The downside of this structure (as skibobdi mentioned) is that the posts table runs the risk of getting very big indeed, but then eliminating the joins should speed the queries up a lot.

          The actual programming of a forum, however, can be quite difficult and if not difficult then deffinately laborious. Good luck, you'll need it 🙂

            Write a Reply...