Ok guys,

I am going to make a forum, but wonder what the best way would be to store the messages. I am going to use mysql for sure, but should I be creating a new table for each new thread? How should I go about organizing these?

    As a general rule, it is bad practice to create new tables or new columns at run time. It's the database equivalent of self-modifying code (read: very ugly). In normal operations you should only be adding or removing rows.

    Google for "database normalization" and read up on how to properly handle complex data structures.

    Also, you might want to look at how other boards do it.

    If this is not for entertainment purposes, consider using an existing board package instead of rolling your own. You'll get a board that is both more reliable and more feature-filled, in less time. I think there is a thread somewhere in the echo lounge (one of the other forums on this site) that dicusses the various PHP-based boards.

      Why are you gonna create a new table for every new thread.

      Why not add new records to that table and display posts and link the tables.

      I also suggest downloading a few free ones to see the database setup as well as how they did it to help you get started.

        I know a lot of people are looking for this info, so I'll post it. This applies to any database, wherever there will be unknown quantities of data. This example is reeeally simple, but it'll show u the basics. You'll get what I'm saying.

        For every table you make, give it a unique ID. Make tables for: User, Thread and Message. For the message table, also give it a thread ID column, into which you put the ID of the thread it belongs to. You can then pull out all the messages by specifying their thread ID - they don't get mixed up with the other records. Put a User ID column in the message and thread tables, too, to associate which user created the thread/post.

        As you can see, the basic ideas are - don't repeat data, and only keep relevent info in one table. Let the database do the hard work by linking all your IDs together. It also makes everything run faster, as a few smaller tables perform better than one very large table.

        This is a really, really basic example of what you need to do. Read up on normalisation, too, as this is what that was. :-P

          i have a forum similar to the idea above that i wrote from scratch a month ago, Except mine had multiforum support. this is how i did it

          TABLES
          - Forums
          - Threads
          - Posts
          - Users or members

          each row in the forums holds different forums. The columns are ID, Name, Thread_IDs. Thread_IDs are pulled out the database. When they are in database they are ALL seperated by commas. When you take them out of the database you explode them into an array. You count up how many elements are in array by using this function _________ cant remember at this point it time ( lol srry). Then you run a while loop

          
          while(numberofthreads!=$counter)
          { 
          
          grab each thread info with a query that takes the counter and grabs through array
          
          Thread_IDs[counter] query or whatever 
          
          then display in a new row and column of a HTML table.
          
          }
          
          

          the same idea is used with posts. the Post_IDs are stored in the threads table 🙂 basically same idea as the threads.

          I guess i must have made a decent DB scheme then because its widely used? I swear i never looked at anyones code or got any structural help!

          😃

          cheers

            Write a Reply...