Jump to content

Query to display posts by friends?


kfernandes29

Recommended Posts

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.

Link to comment
Share on other sites

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!';

}

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.