S
S
samorez7772018-06-11 16:26:56
MySQL
samorez777, 2018-06-11 16:26:56

How to retrieve images from database?

There are 10 pictures on the site. it is necessary to display several pictures for each product from the database.
Pictures will be displayed for some products are the same.
For example, for product 1, pictures 1 and 2. For product 2, pictures 1 and 3.
Table with pictures: Images

ID  img_id  Img
1    1       1.png
2    1       2.png
3    2       3.png

........ Product
table: product
ID  product_id   images_numb
1         1         1,2 
2         2         1,3

...... $img = \R::getall ("SELECT * FROM product JOIN images ON product.product_id
= image.img_id ")
. Are you interested in leaving a catalog of pictures and simply attaching them to the product?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2018-06-11
@gromdron

Adding Egor Skorokhodov to the answer , if you really don’t want to work with ManyToMany models, there is an easier way (as a patch is suitable, but in the future it will be worse).
SQL has such a thing - FIND_IN_SET and you can use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question