TeddyKiller Posted April 4, 2010 Share Posted April 4, 2010 Friends - How can you friend request someone, and accept it then display on page This is appearing to be a big project to me, even though this could be very small.. I'm not entirely too sure how to do this. I'm thinking of having 2 database tables. friend_requests, friends The requests table could be something similar to.. id, request_by, request_to, status id is auto-increment, request_by is who sent the friend request, request_to is who recieved the friend request - so who it was sent to, status would be the status of the request. So.. null/empty etc, accepted, or declined. So when you friend someone, it'll insert a row into that table. Then to accept/decline requests, or to view them. I'll do a query to get the data where request_to is the current users id, where status isn't declined nor accepted. When a user accepts the friend request - it'll change the status to accepted. Then it'll insert a row into the 'friends' table. Then I'm not too sure what happens after that. I don't know what the friends table will look like. Can anyone help? Link to comment https://forums.phpfreaks.com/topic/197546-friends-how-can-you-friend-request-someone-and-accept-it-then-display-on-page/ Share on other sites More sharing options...
jwk811 Posted April 4, 2010 Share Posted April 4, 2010 you could just use the same table as friend_requests and just change the name to friends. then when they are accepted to select their friends just select the accepted ones to show from both the requester and requestee columns to display both. Link to comment https://forums.phpfreaks.com/topic/197546-friends-how-can-you-friend-request-someone-and-accept-it-then-display-on-page/#findComment-1036772 Share on other sites More sharing options...
Jax2 Posted April 4, 2010 Share Posted April 4, 2010 Okay, 2 tables: friend_requests friends friend request is set up like you said: requestID - auto increment request_by (which would be the username or ID of the person requesting the friends) request_to (the username or ID of the person who's friendship is being requested) status (set to 0 if it hasn't been accepted, 1 if it has, or 2 if declined) friend table would be almost the same: friendID username (current person logged in) friend (their friends ID or username) So then, like you said, if someone requests a friend, it adds a row to the database. Current user would go into the request_by, person they want to be friends with would go into request_to, and the status would be set to 0. So, on the users panel, have it do a quick database query, if a record exists in request_to with the current username, and the status is 0 (meaning new) show that user who requested the friendship. if they accept it, change the status to 1, if they deny it, change the status to 2 (so it's not shown again) if they accepted it, add 2 new records to friends. One for each user: I.e., ID name friend 1 | user A | user B 2 | user B | user A From then out, it's as simple as looking up all records where current user = user A and displaying them showing "friend" as the other person. Does that make sense to you? Link to comment https://forums.phpfreaks.com/topic/197546-friends-how-can-you-friend-request-someone-and-accept-it-then-display-on-page/#findComment-1036778 Share on other sites More sharing options...
TeddyKiller Posted April 4, 2010 Author Share Posted April 4, 2010 Oh yeah! How would I display it though.. because sometimes my id eg: 11, could be in request_to.. aswell as sometimes in request_by. I could display the ones I sent, or I got by doing something similar to $query = mysql_query("select * from `friends` where request_by='my id' and `status`='accepted'"); and display the friends display pics where id is "request_to" (displays id instead of usernames) or I can do it the opposite way, using request_to where it has request_by etc. I'm not sure about doing both though. It'd be sort of like.. if($row['request_by'] == my "id"){ display request_to } elseif($row['request_to'] == "my id"){ display request_from } As for Jax2's method, I believe I understand yes. Would that be better than the 1 table method? Link to comment https://forums.phpfreaks.com/topic/197546-friends-how-can-you-friend-request-someone-and-accept-it-then-display-on-page/#findComment-1036786 Share on other sites More sharing options...
Jax2 Posted April 4, 2010 Share Posted April 4, 2010 Personally I think with two tables it would be pretty simple to do. As for displaying it would be easy with the two tables: $sql="SELECT * from friends where userID(current logged in user)=$_SESSION['userID']" (or whatever method you use to show who is logged in) ... $result=mysql_query($sql); while ($row=mysql_fetch_array($result)) { echo "".$row['friend']."<br>"; } that bit would go through all the records and display all friends of whoever is logged in. Link to comment https://forums.phpfreaks.com/topic/197546-friends-how-can-you-friend-request-someone-and-accept-it-then-display-on-page/#findComment-1036795 Share on other sites More sharing options...
TeddyKiller Posted April 4, 2010 Author Share Posted April 4, 2010 Ok, cheers thanks Link to comment https://forums.phpfreaks.com/topic/197546-friends-how-can-you-friend-request-someone-and-accept-it-then-display-on-page/#findComment-1036798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.