0

Hi,

I am working on a script whereby if you are not my friend where by i need to restrict people who are not my friends to view my profile.

for example If I am the logged in user and i am trying to view someone else who is not my friends( i should be denied access with an error message)

The same way as if I am someone's friend in the database I should be able to view their profile.

any help on this please

i have got my table with friend1, friend2 and status = 1 (meaning friendship exist)
AND friend1, friend2 and status =0 ( friendship does not exist and want to show both)

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by oskido2010
0

The MySQL query would look something like this, also basic starting point:

// Basic query to find a relationship
$result = mysql_query("SELECT `status` FROM `relationships` WHERE `friend1` = '$user_id' AND `friend2` = '$friend_user_id' OR `friend1` = '$friend_user_id' AND `friend2` = '$user_id'")or die("Cannot select relationship, error:".mysql_error())
if(mysql_num_rows($result) != 1) {
  // No relationship in db or more than one relationship, show error
} else {
  // Work with the results
}

This is untested code off the top of my head, may need altering.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.