Jump to content

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?

Link to comment
https://forums.phpfreaks.com/topic/284405-designing-database-for-web-shop/
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
Edited by boompa
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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