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>";

?>

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

 

 

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"

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.