M
M
MrColdCoffee2019-11-21 08:21:29
PHP
MrColdCoffee, 2019-11-21 08:21:29

How to implement result pooling in RedBean PHP?

Good day to all!
I ask for help with the implementation of checking the likes of the user in the process of loading the post.
table users :
id | userName
Table posts :
id | postTitle | authorID
table likes :
id | postID | userID I'm
using RBphp.
There is a query:
R::getAll('SELECT p.* ,u.name FROM posts p, users u WHERE p.authorid = u.id AND p.status=1 ORDER BY p.id DESC LIMIT 10');
As a result, we get an array with data about posts, where instead of the author's ID, his name is written.
The likes counter is located in the posts
table In the likes table , the likes themselves are stored.
The question is how can I add the search result of a row in the likes table to the query , where userID= user ID, and postID=posts.id ?
I think it's expensive to do a check in a cycle for each post separately, or is it better to leave it like that?)
Thanks in advance!)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2019-11-21
@SilenceOfWinter

sql - left join

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question