S
S
samorez7772018-06-12 20:42:34
MySQL
samorez777, 2018-06-12 20:42:34

RedBeanPhp How to display images by id?

It is necessary to display pictures by product id..
Two tables:
Product

id title img_id
1  Nike     1
2  Puma     2

images
id  id_img      img
1      1       1.png
2      1       2.png
3      1       3.png

Through findAll I find all the pictures:
$pay = \R::findAll ( 'images', 'id_img ' );
All images are displayed in a loop:
<?php foreach ($pay as $p): ?>
 <img src="../img/payment/<?= $p['img'];?> ">
<?php endforeach;?>

How to formulate a query for output by id?
upon request
$pay = \R::findAll ( 'images', 'id_img = "$all->img_id" '  );

and defining
$all =\R::getAll ("SELECT * FROM product JOIN images ON product.img_id = images.id_img");

and output in a loop outputs an empty array!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
John Doe, 2018-06-24
@rabbit418

<?php
$all = R::getAll ("SELECT * FROM product JOIN images ON product.img_id = images.id_img");
$pay = R::findAll('images', 'id_img = ?', [$all->img_id]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question