Jump to content

Archived

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

thisuser

Designing database for web shop

Recommended Posts

Let's say I want to store price, quantity, description and a pics of the product. So the table will have 5 fields including primary key this means that if a user wants to add 5 pics then I set up my database with 9 columns. Let's say I give the user an upper limit of 10 pics per product so the table would have 15 or so columns. (The pic fields won't actually contain images but only the URL of where the image is)

 

Is this good practice? Or any other ways to set up this kind of db? Or would it be better performance wise to set up another table linked using the primary/foreign key? Any other things I haven't considered?

Share this post


Link to post
Share on other sites

The latter. One product has many pictures. Read up on database normalization.

products
----------
id int primary key autoincrement
quantity int
price decimal
desc text
product_pictures
-------------------
id primary key autoincrement
product_id int -- foreign key to products.id
image_path varchar(2048) -- path to picture in the filesystem

Get product info with pictures:

SELECT p.id, p.quantity, p.price, p.desc, pp.image_path FROM products p JOIN product_pictures pp ON pp.product_id = p.id

Share this post


Link to post
Share on other sites

×
×
  • 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.