I am a new coder and I am wondering what some better options might be for handling images for my gallery website.
Currently here is how I am building the site to handle images:
- Images are not stored in the database - they are just stored in an images folder on the server
- I have an images table (imagesTable) that has 2 columns which contain the image file name (i.e. mypic.jpg), and the product number it is associated with. (Columns: image_name and product_number)
- As there might be multiple images per product number, I have declared both columns in the images table to be primary keys.
- On my products table (productsTable), I have several columns for the product details, and I have a column (product_image_name) for the “primary” display image for the product.
- On my gallery display page, I test for a match on the images table with both of the product number and the image name, and then display that as the main image.
- On the specific product page, I show the main image, and any additional images.
I am now wondering if this is the best approach? I had originally thought the best way would be just to have a third column in the images table for “image_id” which would be a unique identifier and primary key for the image. This would then mean that I change my main image column on my product table from “product_image_name” to “product_image_id” and link accordingly.
Currently I am just using phpMyAdmin for my database tools, until I fully create my admin pages, so I am being extra careful to ensure that my image name used in both tables is the same.
I originally created my database tables from a dump of data from Excel, and I found a couple typos in image names, so I had to go to both tables to update it. In theory, this should not be an issue once I create my admin page for adding/managing images, as I will ensure that it makes changes to both tables.
Any recommendations on how to best accomplish what I am trying to do (as a new coder) would be appreciated.