runnerjp Posted June 24, 2008 Share Posted June 24, 2008 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/111709-solved-checking-if-user-is-allready-a-friend/ Share on other sites More sharing options...
craygo Posted June 24, 2008 Share Posted June 24, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/111709-solved-checking-if-user-is-allready-a-friend/#findComment-573409 Share on other sites More sharing options...
dannyb785 Posted June 24, 2008 Share Posted June 24, 2008 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" Quote Link to comment https://forums.phpfreaks.com/topic/111709-solved-checking-if-user-is-allready-a-friend/#findComment-573450 Share on other sites More sharing options...
runnerjp Posted June 25, 2008 Author Share Posted June 25, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/111709-solved-checking-if-user-is-allready-a-friend/#findComment-574067 Share on other sites More sharing options...
sasa Posted June 25, 2008 Share Posted June 25, 2008 if($found < 1 and $username != $useronline){ Quote Link to comment https://forums.phpfreaks.com/topic/111709-solved-checking-if-user-is-allready-a-friend/#findComment-574072 Share on other sites More sharing options...
dannyb785 Posted June 26, 2008 Share Posted June 26, 2008 lol wtf I have no idea what I was thinking when I posted my reply Quote Link to comment https://forums.phpfreaks.com/topic/111709-solved-checking-if-user-is-allready-a-friend/#findComment-574649 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.