Jump to content

how would i check if user is pending already?


Monkuar

Recommended Posts

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

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.