R
R
Roman2016-10-25 00:50:46
Yii
Roman, 2016-10-25 00:50:46

How to store multiple image URLs in a database?

There is a form in which you can send several pictures at the same time, the question is how to make it possible to store up to 4 pictures in one field?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-10-25
@slo_nik

Goodnight.
Why are there multiple values ​​in one field?
Do you just store images or are they tied to a particular entry in the database?
As an option - two tables.
In one, the name of a group of images, in the second, addresses, each under a separate id. Link tables by group id from the first table.
When writing to the database, first create a group in the first table, then write addresses to the second table and write the group id in the parent_id field.
ps Although you can get by with one table

M
Maxim Timofeev, 2016-10-25
@webinar

2 options:
1 Correct:
there are two tables, for example product and product_image, pictures are stored in the second, each in a separate line, product is associated with product_image through hasMany and product_id
2 option:
yii\helpers\Json will help convert the array with image data in time , which can be written into 1 cell, and then using it to convert back to an array. You can put this logic in beforeSave and in AfterFind

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question