Note that there are some explanatory texts on larger screens.

plurals
  1. POAn efficient database design for a simple forum using php and mysql
    primarykey
    data
    text
    <p>I am in the process of designing a database for forum functionality for my website.After doing some searching on SO and google, I have come up with the following design: <strong>User table</strong></p> <pre><code>Username : varchar(256) Password : varchar(256) </code></pre> <p><strong>Threads table</strong></p> <pre><code>ThreadId : int UserId : int, related to Users table Title : varchar(255) Date : timestamp, when a thread was created </code></pre> <p><strong>Posts table</strong></p> <pre><code>PostId : int ThreadId : int, related to Threads table UserId : int, related to Users table Date : timestamp, when post was made Title : varchar(255) - post title (optional) Body : text - the actual body of a post </code></pre> <p>Even though this serves my purpose, i can't help but think this is not very efficient, especially for selecting all the posts for a particular thread for which it would be necessary to traverse the entire table.</p> <p>From the top of my head, i can think of a design where the <strong>Users table</strong> and <strong>Threads table</strong> remain as they are, but instead of having a single table for the <strong>Posts table</strong>,I create a <strong>Posts table</strong> for every user having the same name as the user.This way retrieving all the posts belonging to a thread is a lot more efficient,since all I need is the userid of the person who started the thread.With this info I search the table with the same name to retrieve all posts for the specific thread.But is it a good idea to make the number of tables I create directly dependant on the number of registered users?What i also want to know is, which one of these designs will scale better,will be easier to manage? Is there a better database design for my requirement?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload