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.

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

Member Avatar for diafol
"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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.