thisuser Posted November 30, 2013 Share Posted November 30, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/284405-designing-database-for-web-shop/ Share on other sites More sharing options...
boompa Posted November 30, 2013 Share Posted November 30, 2013 (edited) 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 November 30, 2013 by boompa Quote Link to comment https://forums.phpfreaks.com/topic/284405-designing-database-for-web-shop/#findComment-1460775 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.