Multiple images per Product

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
styks1987
Forum Newbie
Posts: 8
Joined: Wed Jun 16, 2010 10:03 am

Multiple images per Product

Post by styks1987 »

I am developing a CMS for a company and they want a flyout page that displays multiple images for their product.

The problem I am facing is that I am trying to figure out the best way to setup the database so that the customer can:
// add as many pictures to a product that they want
// delete the images individually from an update page

Should I set up another database table to hold all the images and associate it with the products?
What should be my headings for the image table?

I guess I could set a defined limit on the amount of pictures but I do not really want to do that.

Thank you for your time.
Mike
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Multiple images per Product

Post by aravona »

If you have a second table, you could link the pictures by say the product code or id, and have this as a foreign key in the other table but not a unique key. That way you can call all pictures with a matching id later on and use as many as you like?
styks1987
Forum Newbie
Posts: 8
Joined: Wed Jun 16, 2010 10:03 am

Re: Multiple images per Product

Post by styks1987 »

Thank you for your response.
// How would I setup the structure of that table?

I know how to associate the database tables but I am trying to figure out how to get those images to populate the table without setting headings for each picture.
I guess I would have to setup a query that creates a new column when a new picture is added?

Thanks
Mike
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Multiple images per Product

Post by aravona »

Personally, I would make it as simple as possible, I really dont see you needing much more than a unique id for the image, the id of the product to link to and then a filepath for the image. At least, thats how I would do it if I had to. Others may say otherwise.
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: Multiple images per Product

Post by Reviresco »

I would just do it with the file and directory naming structure.

Have a folder for each product and always use the same naming convention, e.g. productX57, productS-52, etc.

Then for each image, automatically append a number to it, like productX57_1.jpg, productX57_2.jpg, etc. and keep it in the corresponding product folder.

Then all you have to do is look for the directory with the same name as the product, and look inside it to see how many images there are and what they are.

Use the database to keep track of the headings (I'm assuming this means captions or descriptions?) for each product.
styks1987
Forum Newbie
Posts: 8
Joined: Wed Jun 16, 2010 10:03 am

Re: Multiple images per Product

Post by styks1987 »

I think you are on the right track but the person who will be doing the uploading will not want to rename the files. I am doing some experimenting with this and I think it would be best just to leave the database out of it and split it into folders like you suggested.
I might make the folders correspond to the product name I have stored in the DB.

Thanks for you help and suggestions!

Mike
Post Reply