I'm trying to find a way to display multiple sized images for each product on the product page in a e-commerce site. For example I would like to have the all the images for each individual product display in a row thumbnails and when you click on the thumbnail it will display a medium sized image in the main image field and then if you click the main image field a modal dialog appears showing the large image.
I would rather use multiple sized images rather than just trying to resize a large image for thumbnails so the user doesn't have to wait for a large detailed image to load and be resized for thumbnails, that and the thumbnails have to be all the same size etc.
At the moment i have a product_images table that is linked with the products table, though I'm unsure of how to link the small, medium and large images together and load them onto the product page
tables
Products:
--------------------------------------------
-- product_id -- product-name -- etc....
--------------------------------------------
-- 4034677333 -- widget1 --
-- 7088383839 -- widget2 --
--------------------------------------------
Product_images:
------------------------------------------------------------------------
-- product_id -- image_name -- small -- medium -- large
------------------------------------------------------------------------
-- 4034677333 -- 4034677333_0_small.png -- 1 -- 0 -- 0 -- // First image
-- 4034677333 -- 4034677333_0_med.png -- 0 -- 1 -- 0 --
-- 4034677333 -- 4034677333_0_large.png -- 0 -- 0 -- 1 --
-- 4034677333 -- 4034677333_1_small.png -- 1 -- 0 -- 0 -- // Second image
-- 4034677333 -- 4034677333_1_med.png -- 0 -- 1 -- 0 --
-- 4034677333 -- 4034677333_1_large.png -- 0 -- 0 -- 1 --
So at the moment I'm trying things like displaying the thumbnails with
SELECT * FROM product_images WHERE product_id='$id' AND small='1'
And then trying to somehow add the medium image file name that's associated with the thumbnail as a data attribute in an <a>
element wrapped around the thumbnail <img>
when I loop through each query result, but I just can't do it.
I think I'm going about it completely wrong, I don't know. I'm a novice here.