I am working on a blog website and stuck at this:
MySQL
- ‘
cat_list‘ table contains columns:cat_id,cat_name(14 entries), - ‘
post‘ table have several columns wherecategoryis one of them where I need to store the category id in which the blog post was tagged to. the category ids are stored in anarray(19820,83729). [because a blog post can be tagged in multiple categories]
I was trying to search ‘post‘ by one category ID and join ‘cat_list‘ to retrieve the cat name.
Please help me to do this or is there any other alternative database design I should consider?
If your post can be tagged with several categories your table model is wrong. You need an associative table between the blog post and the categories. Remove
category idfromposttable and create a tablepost-categorywith columnspost-idandcategory-id. Then also add indexes on theses two columns to speed up search in both directions (by category or by post).