So im making this app where user could add UP to 3 images to the restaurants database beside the other information (title, address, etc,..)
What would be the best solution for this?
Uploading:
3 file inputs, adding the image paths to the same database table than other information (3 columns, pic1, pic2, pic3 with image paths)?
or
Separate table for image paths, connected to the main table with ID (how fast is that when handling a lot of data)?
Editing:
Deleting / changing images, but there shouldnt be more than 3. How to deal with that in database.
i'd setup image path configuration within my app and only store the image name along with all other fields in the same table.
Personally I would deal with images in a seperate table
The images table could hold all the image related data with a second table called user_images or such to join the two together in searches. The user_images table would have three fields like id, user_id and image_id
This way you can at a later date alter the number of images that a user can upload. This is also a more normalized data structure for your database and allows for much more flexability.
If you have very large data sets this should be more efficient space wise so long as you optimise your sql queries.
You can still check that the user does not have more than 3 images by searching the user_images table for all entries with the user_id belonging to any particular user.
Editing and deleting images is just as simple.