Jump to content


Photo

DB newb ?


  • Please log in to reply
1 reply to this topic

#1 compphenom

compphenom
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 24 March 2003 - 05:23 PM

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

#2 9AF

9AF
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 25 March 2003 - 12:20 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users