Eric1978
Eric1978

Reputation: 83

Mysql database structure webshop

I am building a simple webshop for my portfolio website. In this webshop there are two kind of (main) categories: Movies and Games.

Of course these categories have also need subcategories like: game_type, game_platform, movie_type, movie_quality. My question now is: What is the best way to do this?

For my products and categories i now have 3 tables:

webshop_products (wpID, wpName, wpDescription, wpPrice, wpPicture)
webshop_categories (wcID, wcName)
product_category (wpcID, wpID, wcID) -> this is my join table.

My own idea is to my two extra columns in the table webshop_categories: wcType (ENUM 'sub', 'main') and wcParent (For example the subcategory action can have the games or movies category ID as a parent)

Is this solution a good, or has someone a better idea?

Thanks and greetings Eric

Upvotes: 0

Views: 765

Answers (1)

Kane Cohen
Kane Cohen

Reputation: 1800

You can just add wcParent column which at the same time will be pointing to parent category id AND if it's set it automatically means that it's a sub category - no need for extra wcType column.

Also, remove wpcID in product_category and just set wpID and wcID to primary index. You really don't need an extra column.

Upvotes: 1

Related Questions