There are two tables: user_posts (user_id => post_text) and friends (idUser => idFriend). The first one contains the user id (whose post) and the text of the post, respectively, and the second user id and the id of his friend. So I can not figure out how to make a request to the database to select all the posts of the current user and all the posts of his friends.
Current user posts get like this:
$get_user_posts = "SELECT * FROM user_posts WHERE user_id='$user_id' ORDER BY id DESC LIMIT 10"; $result = $conn->query($get_user_posts); Also got all the friends of this user:
$get_user_friends = "SELECT `idFriend` FROM friends WHERE idUser='$user_id'"; $user_friends = $conn->query($get_user_friends); Total is the current user ID and his records, as well as an array with ID of all his friends. And here it is not clear to me how to make a request to the database:
$get_posts = "SELECT * FROM user_posts WHERE user_id='$user_id' AND user_id='все айди друзей' ORDER BY id DESC LIMIT 10"; to select all posts of the current user and another user if this is his friend. In this case, I recently, so please tell me how I can implement this method of displaying news, or if I’m doing something wrong, how is it better and right to do it? Thank.
select * FROM user_posts WHERE user_id=$user_id OR user_id IN(SELECT idFriend FROM friends WHERE idUser=$user_id)- Mike