jdowen Posted July 25, 2013 Share Posted July 25, 2013 (edited) 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. Edited July 25, 2013 by jdowen Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted July 25, 2013 Share Posted July 25, 2013 where does $logOptions_id come from and is it an array? Because if $friendArray is an array you probably don't want to compare it to $logOptions_id. 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. Quote Link to comment Share on other sites More sharing options...
jdowen Posted July 25, 2013 Author Share Posted July 25, 2013 $logOptions_id holds the ID of the current logged in user. Quote Link to comment Share on other sites More sharing options...
andy1212 Posted July 25, 2013 Share Posted July 25, 2013 How does the user toggle through the friend only or public option, through a list menu, 2 buttons, 2 radios, 2 checkboxes? Quote Link to comment Share on other sites More sharing options...
jdowen Posted July 25, 2013 Author Share Posted July 25, 2013 @andy1212 they toggle through via a dropdown on their settings page. If they want friends only to see info, then "fri" is added to privacy_opt field in the database. If they want public it is just left as empty. Quote Link to comment Share on other sites More sharing options...
Solution jdowen Posted July 25, 2013 Author Solution Share Posted July 25, 2013 Doesn't matter now, I solved the problem with && !in_array($logOptions_id,$friendArray) Quote Link to comment Share on other sites More sharing options...
andy1212 Posted July 25, 2013 Share Posted July 25, 2013 (edited) Ok I'm not very familiar with PDO and it looks like you're trying to accomplish this using PDO queries. I laid out how I would set up the functions, dropdown menu, grabbing the data from the database to show which option the user has selected and how to allow the user to send whatever option they choose to the database, which will update the option selected in the dropdown. I'm sure you can take the code I've shown and get an idea of how it should function and change some things to PDO where needed. in your user.func.php file or where ever you're putting your functions, (remember if you're function is on a separate page, to include it on the page you want to use the function on.) function user_data($id){ $args = func_get_args(); unset($args[0]); $fields = '`'.implode('`, `', $args).'`'; $query = mysql_query("SELECT $fields FROM `user_optionsc0nf` WHERE `id`=".$_SESSION['id']) or die(mysql_error()); $query_result = mysql_fetch_assoc($query); foreach ($args as $field) { $args[$field] = $query_result[$field]; } return $args; } on the page where the user chooses a privacy option, this code will select what option they chose so be it, select, public or friendsonly $id = $_SESSION['id']; $data = user_data($id, 'privacy_opt'); on the page where the user can choose which privacy option they want in the form. <select name="privacydrop"> <option value="select" <?php if ($data['privacy_opt'] == 'select') echo 'selected="selected"' ?>>Select a privacy option</option> <option value="public" <?php if ($data['privacy_opt'] == 'public') echo 'selected="selected"' ?>>Public</option> <option value="friendsonly" <?php if ($data['privacy_opt'] == 'friendsonly') echo 'selected="selected"' ?>>Friends Only</option> </select> on user.func.php page or seperate page function update_user($privacy_opt) { $privacy_opt = mysql_real_escape_string($privacy_opt); mysql_query("UPDATE `user_optionsc0nf` SET `privacy_opt`='$privacy_opt' WHERE `id`=".$_SESSION['id']); } Code to perform the task of sending the chosen privacy option to the database to the field privacy_opt. if (isset($_POST['privacydrop'])) { $privacydrop = $_POST['privacydrop']; $errors = array(); if ($privacydrop == 'select') { $errors[] = 'You must select a privacy option'; } if ($privacydrop == 'public') { $privacy_opt = 'public'; } if ($privacydrop == 'friendsonly') { $privacy_opt = 'friendsonly'; } if (!empty($errors)) { foreach ($errors as $error) { echo $error '<br />'; } } else { update_user($privacy_opt); header('Location: whatever_your_page_is_called.php'); exit(); } } Edited July 25, 2013 by andy1212 Quote Link to comment Share on other sites More sharing options...
andy1212 Posted July 25, 2013 Share Posted July 25, 2013 Oh ok awesome! Quote Link to comment 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.