Help with small PHP application

They have: 1 posts

Joined: Jul 2009

Hey All, first post! Smiling

I need to be able to upload multiple images per database entry and then output them again in a small image gallery per entry. Very similar as to how it is done here (http://www.ebuyer.com/product/128045)

Adding all the other information such as title, description, price etc is not going to be a problem for me, just as this type of thing seems to have been done a million times I am just looking for some guidance or some previously written code that may be used often with this type of thing.

Any help would be greatly appreciated, if you require any additional information I will provide it! Smiling

Thanks all so much,

Quantum23.

They have: 21 posts

Joined: Nov 2008

can you post the url where your script is currently running ?

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Basically, you will have a table with the content (what you are used to doing with the title,price, etc):

tblItems
========
ID auto-incrementing integer as primary key
Title
Description
Price
Other

Now you will have a table to hold the information about the files.

tblFiles
========
ID auto-incrementing integer as primary key
ItemID The tblItems.ID (foreign key) of the item this image goes with
Order and integer to sort by for ordering the images (if you code that)
FileName The name of a file that is uploaded to a media directory
AltText The AltText for the image / caption
ThumbName A resized copy for use as thumbnails (see http://www.imagemagick.org/script/convert.php)

Now when you load up the item data, then do a second query to get the image information that goes with it.

-Greg

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

PS, for the heck of it. say you need a list of all items AND the image from the FIRST file uploaded with it (the primary image), and assuming you don't need AltText as the ItemTitle will work for that in a listing of items. You can use the following. I have it broken up across lines for easier reading here.

SELECT
  i.*,
  (SELECT
     f.`Thumb`
   FROM
     `tblFiles` AS f
   WHERE
     f.`ItemID`=i.`ID`
   ORDER BY `Order`
   LIMIT 1
  ) AS Thumb
FROM
  `tblItems` AS i

Now you will have all the item fields plus "Thumb"

-Greg

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.