Answer the question
In order to leave comments, you need to log in
How to add multiple photos to database?
I parsed a site with products, and each product has a photo, a different number. One product has 3, another has 5, the third has 10, etc.
How can I write down the addresses of all the photos for the product in the database. Create the maximum number of columns how many and the maximum number of photos for the product? Or is there another way?
Answer the question
In order to leave comments, you need to log in
In order not to complicate the database schema with another table, if you do not need to frequently search for a product at the address of its image, you can simply make a type field text
and add image addresses into it through a separator, say, through a non-printable ASCII character, or through a space, if each URL is before this run through urlencode()
or encode in JSON an array of links to images and store a json string:
$images = [
'https://site1.ru/images/product.php?getimage&id=123&img=345',
'https://site2.ru/images/shkaf.jpg',
'https://admin:[email protected]/admin.php?img=234',
];
$imgString = json_encode($images);
// строку $imgString положить в единственное поле для картинок в БД .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question