I am making a social networking platform. And I just wanted to know of a way to filter out only the post of a user's friends.
Currently, the way I am filtering the posts is by selecting all posts but showing only those posts which are from the user's firend somewhat like this:
$select = $con->query("SELECT * FROM posts ORDER BY timestamp DESC");
while($postassoc = $con->fetch_assoc()){
$postby = $postassoc['user'];
$friendof = $con->query("SELECT id FROM friends WHERE 'from'='$user' AND 'to' ='$postby' OR 'to'='$postby' AND 'from'='$user' AND 'auth'='1'");
If($friendof != 0){
//show post
}
}
Assuming there are no errors, this way will take a lot of time on the long run. Is there any better and more efficient method?