user3177012
user3177012

Reputation: 681

One Or Multiple Tables For Multiple Users

I'm creating a website where multiple users can register and post news articles, but I was wondering if all of the articles should go in one single table or if each user should get their own table. I'm guessing that the first option is going to be the simplest (and probably the best) but how many posts is too many for one table? I mean if all of the articles are fairly long, at what point does the site begin to slow down when using PHP to extract the data?

Also, similar to my first question, if each user can set multiple categories for their news profile, should all of the categories go in one table:

table_categories : id, category_name, belongs_to (user_id)

Or again, should a seppreate categories table be assigned for each user?

Upvotes: 0

Views: 159

Answers (1)

Anshul Goyal
Anshul Goyal

Reputation: 76867

The way I see it, you need 5 tables, one each for category, post and user, and 2 tables to store possible (many-to-many) relationship between user-category and post-category.

category - category_id, category_name, description
user - user_id, user_name, user_details
post - post_id, user_id, text
user_category_mapping - user_id, category_id
post_category_mapping - post_id, category_id

EDIT

If you want to have only one category per post, following four tables should suffice

category - category_id, category_name, description
user - user_id, user_name, user_details
post - post_id, user_id, text, category_id
user_category_mapping - user_id, category_id

Similarly, if you want to implement a subcategory functionality, you can alter the category table as below

category - category_id, category_name, description, parent_category_id

Upvotes: 1

Related Questions