Jump to content

Recommended Posts

Hello.

I have a system worked out where I have 2 columes for friends in my database (login_info).

One of these is requests and the other is friends. Each request/friend is seperated with a underscore (_). I use the explode() function to seperate the friends/requests into a array. My only problem is I want to display the a different text  if the user has sent a requests or is already friends with the user. I tried to do this using the array_search() function and converting it into a boolean (with the boolean cast). It doesn't seem to be working.

<?php 
$query = mysql_query('SELECT friends, requests FROM login_info
WHERE user = \'
' .$userget .'\'');
$friend = mysql_fetch_assoc($query);
$req = explode('_', $friend['requests']);
$friends = explode('_', $friend['friends']);
if((bool)array_search($userget, $friends) && (bool)checkarray($userget, $req))
{
echo '<a href="?p=add&user='.$userget .'"> Add As Friend </a>';	
}
if((bool)array_search($userget, $req))
{
echo 'Friend Request Pending';	
}
if((bool)array_search($userget, $friends))
{
echo $userget .'Is Your Friend' .$user_log .'!';	
}


?>

Any help?  :confused:

If you remove those casts I'm pretty sure it would work. array_search will return false if it doesn't find a match.

 

On second thought, it'd probably be safer to do it like this, just to make sure it found a match:

if(array_search($userget, $friends) !== false && checkarray($userget, $req) !== false)
{
echo '<a href="?p=add&user='.$userget .'"> Add As Friend </a>';	
}
if(array_search($userget, $req) !== false)
{
echo 'Friend Request Pending';	
}
if(array_search($userget, $friends) !== false)
{
echo $userget .'Is Your Friend' .$user_log .'!';	
}

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.