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)

Recommended Answers

All 2 Replies

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.

Thanx so much m8, will try the code tomorow, much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.