Multiple Categories?

I want to be able to add something into multiple categories.

Currently, when I add something to the database, I choose a category, for example: “Red” with the ID of 1

That item then belongs to the Red category.

I have a category page which selects everything for category 1 “Red”.

All red items are displayed on page.

What I want to know is, how to do multiple categories?

What if an item is Red and Blue?

Category 1 - Red and Category 2 - Blue

How do I insert it into the database to be 1,2 and how do I select that item as just 1 for the Red category but then it is also in the Blue category when you look there?

Thanks! :slight_smile:

Hope my example was okay :x

You need Three tables.

categories

cat_id
cat_name
cat_nameseo

products
prod_id
prod_name
prod_nameseo
prod_desc

prod_cat
cat_id
prod_id

The prod_cat table will allow you to list the product id many times to different categories. Hope this helps (Same Advice as Kalon)

<snip/>

You could have a separate table called “prodCats” which has a 1 to many relationship with your “products” table. prodCats would have a record for each product and the categories it is in. You could have foregn keys in prodCats to make sure that the prodId and catId exists in your “products” and “categories” tables.