kfernandes29 Posted April 12, 2012 Share Posted April 12, 2012 I need a little help. I currently have three tables and I want to display all posts made by my friends. These are the tables and their columns. In "follows", user_id is mine and "follow_id" is the id of the user I added to my friends list. - users --id --username --password - posts --post_id --user_id --message --timestamp --views - follows --id --user_id --follow_id --timestamp Any help would be greatly appreciated! Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/260816-query-to-display-posts-by-friends/ Share on other sites More sharing options...
kfernandes29 Posted April 12, 2012 Author Share Posted April 12, 2012 OK, I have a bit of progress but it's not functioning totally right. It's listing all posts made, not just posts WHERE my $userid is the follow_id in the "follows" table. Some help, please? :-) <?php session_start(); include("conn.php"); $userid = $_SESSION['userid']; $result = mysql_query("SELECT po.user_id, po.message, po.timestamp, fo.user_id, fo.follow_id FROM posts AS po, follows AS fo WHERE fo.follow_id = '$userid' ORDER BY timestamp DESC"); if ( mysql_num_rows( $result ) > 0 ) { while ($info = mysql_fetch_array( $result )) { echo 'Post : '.$info['message']; echo "<br />"; echo 'Timestamp : '.$info['timestamp']; echo "<br />"; echo "<br />"; } } else { echo 'No results found!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260816-query-to-display-posts-by-friends/#findComment-1336795 Share on other sites More sharing options...
fenway Posted April 15, 2012 Share Posted April 15, 2012 That's because you're missing a JOIN condition. Quote Link to comment https://forums.phpfreaks.com/topic/260816-query-to-display-posts-by-friends/#findComment-1337629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.