Jump to content

Friend System


creata.physics

Recommended Posts

Hello All,

 

I'm making a networking script for my cms to allow users to befriend each other, I've got adding each other as friends down, that is no longer an issue.

My issue is displaying friends on a profile page.

 

Say Matt added Frank, and frank accepted the request, well on Matts page it'll show frank as a friend, but on franks page it won't show Matt as a friend.

 

My MySQL table has just 4 Rows

 

id | user_id | friend_id | approved

 

-id is a primary unique key

-user_id is who sent the reuqest

-friend_id is the id of the user the request was sent to

-approved is the status, 0 for no accepted, 1 for accepted.

 

On the user profile page, this is the sql query used to generate the friends list

$friends = $db->get_table("SELECT * FROM zxt_friends WHERE user_id = '{$u['id']}' AND approved = '1'");
foreach ($friends AS $friend)
{
$friend['friend_name'] =$zext->user_cache[$friend['friend_id']]['username'];
$avatar = $zext->user_cache[$friend['friend_id']]['avatar'];
        $friend_html = $friend['friend_name'].$avatar;
}

 

Before I tried using a different sql query, it looked like this:

$friends = $db->get_table("SELECT * FROM zxt_friends WHERE user_id = '{$u['id']}' OR friend_id = '{$u['id']}' AND approved = '1'");

 

But the approved status was ignored, and it was all kinds of messed up, on my page it would show that Matt is indeed friends with frank, and a member that had not approved the reuqest yet, and on Frank's page it showed that he was a friend with himself when that wasn't even the case.

 

I've looked at array_push but I can't seem to figure out the query or what I need to add the the loop, any help would be much appreciated.

 

Thanks, Matt.

Link to comment
Share on other sites

Since there is no edit button for me for some strange reason and it seems I don't have the ability to mark topic as solved I can't do it myself.

 

Sorry for the double post, but if any mod or something wants to mark this topic as solved feel free to do so for i have fixed the issue.

 

Thanks, Matt.

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.