creata.physics Posted May 30, 2011 Share Posted May 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237836-friend-system/ Share on other sites More sharing options...
creata.physics Posted May 30, 2011 Author Share Posted May 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237836-friend-system/#findComment-1222202 Share on other sites More sharing options...
spiderwell Posted May 30, 2011 Share Posted May 30, 2011 i think the sql isnt quite right, perhaps you need it like this: "SELECT * FROM zxt_friends WHERE (user_id = '{$u['id']}' OR friend_id = '{$u['id']}' ) AND approved = '1'" putting brakets around the OR Quote Link to comment https://forums.phpfreaks.com/topic/237836-friend-system/#findComment-1222226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.