So, I was building a blog, and wanted to assign categories to blog posts. What should be the structure of the post table? Should there be fields for each category(or its id) with boolean datatype? Or should all the category ids be limited to a single field?

(23:45:03) hauk: I guess you are over the best part of your life when 4-year-olds say "Are you an evil man?"(23:46:19) hauk: and "Ima punch you in the pecker"

And add a "Category" field which accepts numbers into your "Post" table. There is good in that too. Imagine you wanted to change the name of a category? You would have to edit the name in every single post ( Could be done with a script too ). Now you just have to change it in one place. Also numbers are sorted/searched faster than strings.

And add a "Category" field which accepts numbers into your "Post" table. There is good in that too. Imagine you wanted to change the name of a category? You would have to edit the name in every single post ( Could be done with a script too ). Now you just have to change it in one place. Also numbers are sorted/searched faster than strings.

Agreed, I already understand that, but how do I assign multiple categories to a single post? Like a Post that goes " Hello, this is shit introducing itself to pendejo." , can have multiple categories like shit, introduction and pendejo.

(23:45:03) hauk: I guess you are over the best part of your life when 4-year-olds say "Are you an evil man?"(23:46:19) hauk: and "Ima punch you in the pecker"

Good question!Let's keep the "Category" table but forget about adding a "Category" field in the "Post" table. Instead we create a new table let's call it X. You could use that table to pair Posts with Category or with other words the ID field of your Post table with the ID field of the Category table.

For example:You have two posts "The PHP language" which is in the "Web" & "Programming" and the " HTML 5 " which is just in the "Web" category. The newly created table would look like this:

Gatito wrote:Good question!Let's keep the "Category" table but forget about adding a "Category" field in the "Post" table. Instead we create a new table let's call it X. You could use that table to pair Posts with Category or with other words the ID field of your Post table with the ID field of the Category table.

For example:You have two posts "The PHP language" which is in the "Web" & "Programming" and the " HTML 5 " which is just in the "Web" category. The newly created table would look like this: