Вопрос

I'm making a car dealer website, don't have much experience with coding though. I have a form with multiple selects and text areas and i also need to add 3-5 images to this form to display later with the car info. How should my database look like. carID carMake carModel etc. but how to i save these 3-5 images to this database? should i make separate inputs like image1 image2 etc upload them and then save url's to database?. I stumbled upon an "blueimp jQuery File Upload" it seems nice etc, but i don't understand how to save the multiple file array to the database with the other car info. Any ideas? Or examples how to properly perform this?

Это было полезно?

Решение

Between CarTbl and CarImagesTbl is a one-to-many relationship. The primary key of CarTbl will be foreign key in CarImagesTbl, this way you will be able to identify to what car does belong each image. enter image description here

After you insert the car into database, you get its primary key, and looping trough the array of imagesURL, you insert the values in the CarImagesTbl. To get the images for one specific car, you do a join between the tables

Select URL,CarID
From CarImagesTbl ci, carTbl c
Where c.carId = ci.carId_FK 
and c.carId = wantedCarId
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top