On my website a user can post comments and group these into categories.
e.g.
category: good quotes
links: "some quote 1", "some quote 2", and so on.
So the number of categories and comments are determined by the users.
I’m thinking how I should organize this in the mysql database.
I can’t have one table for each category because there would be A LOT of categories.
But how could I organize this in a table?
should a category be in one column, and a comment be a row? or should it be the other way around?
But then, isnt it a bad practice to increase the number of columns after you have defined the table?
Any suggestion would be helpful!
You can create a table for categories and a table for comments (so one category is one row, and one comment is one row in their respective tables). You can also need another table with two columns — an ID for category rows, and an ID for comment rows.
Then, to indicate that a comment belongs to some category, you add a row to the last table. For instance if a comment with ID 42 belongs to categories with IDs 6 and 8, you add the rows (42, 6) and (42, 8).