database structure for the user hide their personal info
How is the database structure for the user hide their personal info like hp, email address and full name?
Should I create a table (hidden_info) to keep all the private personal info of the users when the users set them to be private through my website.
Then on the user-profile.php page, use mysql to select * on hidden_info_table where user==$username, th开发者_运维知识库en use other mysql to select and display the info which are not listed on hidden_info_table?
That will be a lot of works, is there any other better way to construct the database for hiding user personal info feature?
I wouldn't use a separate table. I would have a settings table separately which would contain that privacy options they have available.
Settings
SettingId int
SettingName varchar(100)
UserSettings
SettingId int
UserId int
Setting's could be HideEmail, HideRealName, HidePhoneNUmber for example and you could get the user settings when the user authenticates and store those in session state as an string array (or a custom model)
You could then query the users settings like so:
SELECT SettingName
FROM UserSettings
LEFT JOIN Settings
on UserSettings.SettingId = Settings.SettingId
WHERE UserId =1
This would return a list of settings for the current user. This should be fairly easy for you to work out the PHP side of things from this.
- Store result in string array
- Check if a YourSetting is present in the array, if it is don't show that element
Once you have your array just check if a value exists and do your required logic
if (!in_array("HideEmail", $results)) {
echo "Show email address here";
}
Create a column after email called email_hidden
SELECT * FROM user_info WHERE userID = $ID
<?php
if( !$user_info['email_hidden'] ) { echo $user_info['email'] }
?>
Duplicate for other fields
This is the simplest method, though not the most efficient.
精彩评论