Jump to content

[SOLVED] checking if user is allready a friend


runnerjp

Recommended Posts

ok so in my db i have this

 

friendname    username

  admin          emma

  emma          admin

 

 

easy set up really....

 

so on a users profile i have this

 

<?php
echo "<a href='index.php?page=friendrequest&user=$username'>Add as Friend</a>";
?> 

 

how can i only display this if a user is not friends with a user or its that users profile??

 

 

if

user == ?

 

else

 

show <?php

echo "<a href='index.php?page=friendrequest&user=$username'>Add as Friend</a>";

?>

Link to comment
Share on other sites

I would assume username is the current person doing the browsing and $friendname will be used for the person. With that said try something like this

<?php
$sql = "SELECT `friendname` FROM `tablename` WHERE `username` = '$username' AND `friendname` = '$friendname'";
$res = mysql_query($sql) or die(mysql_error());
$found = mysql_num_rows($res);
if($found < 1 || $username != $friendname){
echo "<a href='index.php?page=friendrequest&user=$username'>Add as Friend</a>";
}
?>

 

Ray

 

 

Link to comment
Share on other sites

I would assume username is the current person doing the browsing and $friendname will be used for the person. With that said try something like this

<?php
$sql = "SELECT `friendname` FROM `tablename` WHERE `username` = '$username' AND `friendname` = '$friendname'";
$res = mysql_query($sql) or die(mysql_error());
$found = mysql_num_rows($res);
if($found < 1 || $username != $friendname){
echo "<a href='index.php?page=friendrequest&user=$username'>Add as Friend</a>";
}
?>

 

Ray

 

 

 

This is correct, except I believe it should be $found < 1 || $username != $friendname

 

I'd also suggest making it $found == 1, not that it needs to be, it's just better for visualizing what's going on "If we aren't friends and this user isn't me, then display the link"

Link to comment
Share on other sites

ok i did this

 

<?php
$sql = "SELECT `friendname` FROM `friends` WHERE `username` = '$useronline' AND `friendname` = '$username'";
$res = mysql_query($sql) or die(mysql_error());
$found = mysql_num_rows($res);
if($found == 1 || $username != $friendname){
echo "<a href='index.php?page=friendrequest&user=$username'>Add as Friend</a>";
}
?>

 

with

 

$username=$_GET['username']; --- getting the users profile name

$useronline= get_username($_SESSION['user_id'] -- getting th username of the user logged in

 

 

but it still displays the link no matter if the are friends or not

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.