0

Hi guys!

I have a website where users can follow each other. I want to create a stream/feed where posts and updates releated to friends will show. So in "theory" something like this:

    if friend1 and friend2 == true
    - > show posts from entries database
    else
    - > don't show anything

SQL:

bhost_userfollow
id, follower_u_id, following_u_id

bhost_entries
e_id, title, contents, u_id

I have seen people using what they call a "JOIN." This looks interesting, but I can't really manage to implement it right. So any tips, ideas and helpful contributions will be appreciated.

Edited by sigvewinter

3
Contributors
2
Replies
31
Views
4 Years
Discussion Span
Last Post by diafol
0

select u.,e. from bhost_userfollow u, bhost_entries e where u_id=following_u_id and follower_u_id= (the USER ID)

..while...
echo title ..content..

0
"SELECT b.*, f.following_u_id AS following FROM bhost_entries AS b INNER JOIN bhost_userfollow AS f ON b.u_id = f.follower_u_id WHERE f.follower_u_id = $user_id"

$user_id is the id of the current logged in user.

You could expand on this with another INNER JOIN linked to the 'following' user's name if you have a 'users' table. For example:

"SELECT b.*, f.following_u_id AS following, u.username FROM bhost_entries AS b INNER JOIN bhost_userfollow AS f ON b.u_id = f.follower_u_id INNER JOIN users AS u ON f.following_u_id = u.user_id WHERE f.follower_u_id = $user_id"

Not tested

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.