EDIT :: I SOLVED IT ! The solution is below.
Hello!
I’m trying to create a user feed, but I am stuck. The code below allows me to get a user’s posts, but I also want to show his friends’ posts in the feed. Let’s say there are posts written by user2 and user3, I want them to show up on the user1’s feed (user1 is the friend of the user2 and user3)
I think I’ll have to use a JOIN but I couldn’t figure it out.
Here’s my database schema.
user_status table
status_id
user_id
status
status_date
friendship table
friendship_id
friend_one (FK from users table)
friend_two (FK from users table)
I’m using a MySQLi wrapper class.
$users = $db->rawQuery('SELECT * from user_status where user_id=? ORDER BY status_date DESC', Array($userid));
$db->orderBy("status_date", "desc");
foreach($users as $feed) {
echo $feed['status']."<br>";
}
EDIT : I solved it.
$iamvery = $db->rawQuery("SELECT user_status.user_id, user_status.status from user_status JOIN friendship ON friendship.friend_two =user_status.user_id");
foreach ($iamvery as $tired) {
echo $tired['status'] . "<br>";
}