Monkuar Posted December 22, 2011 Share Posted December 22, 2011 So let's say if contact_name wants to add member_name as a friend, how would i make it say user is already pending? what variables to check? or should i make friends table and a friends_pending table? Quote Link to comment https://forums.phpfreaks.com/topic/253689-how-would-i-check-if-user-is-pending-already/ Share on other sites More sharing options...
scootstah Posted December 22, 2011 Share Posted December 22, 2011 Select the data from the table and then see if pending == 1? Quote Link to comment https://forums.phpfreaks.com/topic/253689-how-would-i-check-if-user-is-pending-already/#findComment-1300539 Share on other sites More sharing options...
Psycho Posted December 22, 2011 Share Posted December 22, 2011 Select the data from the table and then see if pending == 1? To elaborate on scootstah's suggestion: YOu must have some way of knowing that a friend request is pending. As scootstah alluded to you don't need separate tables - just one table with some way to identify when requests have been confirmed or not. This could be a column for confirmation_date or an explicit column to identify if the request is pending/confirmed. Personally, I would use a field called "confirmed" where the 0 stands for pending and a 1 is confirmed. But, that's more a personal preference. Anyway, when you build that page I assume you would exclude users that have already been confirmed. So, you need to pull users that have never been requested or where the request is pending. You might also need to figure out what you are going to do with requests that have been rejected - if you offer that ability. So, to get the appropriate records you would need to modify the current query. How that would be done would be dependent upon your current DB configuration. Here is one general example: SELECT users.*, friends.confirmed FROM users LEFT JOIN friends ON users.id = friends.friend_id WHERE friends.user_id = $userID AND friends.confirmed <> 1 That will pull a list of all users where there is no confirmed friend record for the user specified in the $userID variable. Then in the code to build the page you would use the value of the 'confirmed' field to change how the records are displayed. For users where there has never been a friend request, the value will be null. For users where there is a pending friend request the value will be 0. I would probably check for the zero with an explicit type comparison (i.e. three equal signs '==='). while($row = mysql_fetch_assoc($results)) { if($row['confirmed'] === 0) { //This user has a pending friend request } { //A friend request has never been sent for this user } } Quote Link to comment https://forums.phpfreaks.com/topic/253689-how-would-i-check-if-user-is-pending-already/#findComment-1300577 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.