Sackling
Sackling

Reputation: 1820

Best way to store product colors in a database

I am working on an online jewelry store website. One of the requests is that from the back end a color/colors can be chosen for a single piece of jewelry so that users would be able to sort/view only items that are for instance green.

What is the best way to store this in a database? Should this be done with 3 tables:

  1. product table (already exists)
  2. color table : each field has a color
  3. table that matches the product is with the color id

Is this the correct way to do it? I am using php and mysql but I think this is just a pretty standard database question.

Upvotes: 1

Views: 1040

Answers (2)

Madara's Ghost
Madara's Ghost

Reputation: 174957

Yes, your solution with a many-to-many relationship between tables sounds good for your case. You can then easily JOIN the tables to get information out of the IDs.

Upvotes: 2

Marcus
Marcus

Reputation: 12586

Yes, that's an appropriate way to do it.

Upvotes: 0

Related Questions