0

I'm currently in the middle of developing a privacy options features which will allow members of my site to toggle whether their information is visible to friends only or to the public.

I'm doing this with PHP. When the privacy_opt variable is set to "fri" though, which means friends should only be able to see the content, the content isn't hidden to the public.

I'm using the following PHP code.

<?php
$sqlo = "SELECT * FROM user_optionsc0nf WHERE id='$id' LIMIT 1";
$opt_query = mysqli_query($db_conx, $sqlo);
// ------- WHILE LOOP FOR GETTING THE MEMBER DATA ---------
while($row = mysqli_fetch_array($opt_query, MYSQLI_ASSOC)){ 
    $privacy_opt = $row["privacy_opt"];
}
if ($privacy_opt == "fri" && $id != "$logOptions_id" && $friendArray == "$logOptions_id"){

echo "Only this person's friend can see this information.";
} else {
echo $website, $youtube, $locationInfo;
}
?>

The $friendArray variable contains the users friends ID's in the form of 51, 100, 22, etc. $logOptions_id holds the ID of the current logged in user.

Erman Belegu
  • 4,074
  • 25
  • 39
James
  • 576
  • 2
  • 8
  • 20
  • Normalize your database: store each user/friend as an individual row in a friends table in your database, and use a join – Mark Baker Jul 25 '13 at 22:02
  • Thanks Mark. But is there a way of doing this without doing all of that? – James Jul 25 '13 at 22:03
  • There is, but why not do it properly in the first place rather than ask people to give you kludgy, inefficient alternatives? Where do you get your $friendArray from in the first place? – Mark Baker Jul 25 '13 at 22:04
  • In all fairness, I developed the site years back and it has a lot of friend data stored that way now. I would rather get this feature sorted then switch further down the line. – James Jul 25 '13 at 22:05
  • If you don't sort it now, you'll never get round to sorting it further down the line.... there'll always be some other excuse – Mark Baker Jul 25 '13 at 22:07

1 Answers1

1

You need to use in_array

&& !in_array($logOptions_id,$friendArray)
cmorrissey
  • 8,493
  • 2
  • 23
  • 27