I use redbean php. the user likes, it is written into the 'post' table as there is a common table 'user2like' where the post id is written and the user id is the structure user2like

id

user_id

post_id

I can not understand how to check that the user has put a certain post Like I tried to check but it turns out that he puts all posts as certain

cycle

foreach ( $pjk as $posting ) { $like=R::findOne('user2like', 'post_id = ? AND user_id=?', array($posting['id'], $_SESSION['logged_user']->id)); if (/*не могу понять как проверить*/) { $l= 'вы уже поставили' ; } echo '<div class="col-auto" id="text_posting_user" data-id="'.$posting['id'].'" style="padding: 1.7em; padding-bottom: 0;"> <div class="text_p"><p>'.$posting['post'].'</p></div> <hr style="margin-bottom: 0.5rem;"> <div class="b_funk_post"> <table> <tr> <td><div class="like" data-id="'.$posting['id'].'">'.$posting['like'].'</div>'.$l.'</td> </tr> </table> </div> </div>'; } 
  • I do not know how to set several conditions in your means of communicating with the database, but do you need to look for the post_id=? and user_id=? entry post_id=? and user_id=? post_id=? and user_id=? ... - Mike
  • if (R :: findOne ('user2like', 'post_id =? AND user_id =?', array ($ posting ['id'], $ _SESSION ['logged_user'] -> id))) did not help anyway, even on those posts where I didn’t like Like - Alexander Zakharov
  • Then, instead of the inscription, print what the findOne function returned to you. Maybe then it becomes clear that she returns that the condition is considered true - Mike
  • $ like = R :: findOne ('user2like', 'post_id =? AND user_id =?', array ($ posting ['id'], $ _SESSION ['logged_user'] -> id)); $ l = $ like; so it displays an array of data, and displays exactly where the like is, how to make a condition? if I make a condition, it is displayed on all records and on those where I didn’t like - Alexander Zakharov

1 answer 1

Can help someone. I apologize for the sloppy

  foreach ( $pjk as $posting ) { echo '<div class="col-auto" id="text_posting_user" data-id="'.$posting['id'].'" style="padding: 1.7em; padding-bottom: 0;"> <div class="text_p"><p>'.$posting['post'].'</p></div> <hr style="margin-bottom: 0.5rem;"> <div class="b_funk_post"> <table> <tr> <td><div class="like" data-id="'.$posting['id'].'">'.$posting['like'].'</div>'; if(R::findOne('user2like', 'post_id = ? AND user_id=?', array($posting['id'], $_SESSION['logged_user']->id))){ echo 'уже нажимали'; } echo '</td> </tr> </table> </div> </div>'; }