Jump to content

DB newb ?


compphenom

Recommended Posts

I have a question with regards to a database\'s structure. I am not all that proficient with databases, but have managed to get into a situation where I am building a website in PHP and now need to connect to a database.

 

I have a table with productId, productName, productTitle, productDescription, productPrice, etc. The problem I am running into is that each product comes in any one of 16 colors, however not all. Product A may come in 12 colors while product B might come in all 16 colors and product C comes in only 6 colors. I am trying to dynamically fill a list box with each product\'s available colors, but I do not know the database structure to accomplish this.

 

Any comments welcome, I hope I have explained this adequately.

 

- Kevin

Link to comment
https://forums.phpfreaks.com/topic/262-db-newb/
Share on other sites

Hi

Hi Kevin

 

You will need to create another table called Product Colour for example with the following structure:

 

id - (autonumber) - primary key

colour - (varchar)

productid - foreign key

 

You will need to have a one-to-many relationship between the tables \'Product\' (one side) and \'Product Colour\' (many side) with productid as the foreign key in table \'Product Colour\'. In this new table you can then associate a colour to each specific product.

 

This should resolve your prob.

 

Hope this is ok.

 

RB

Link to comment
https://forums.phpfreaks.com/topic/262-db-newb/#findComment-783
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.