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
https://forums.phpfreaks.com/topic/260816-query-to-display-posts-by-friends/
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!';

}

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.