I have a simple php web app. I need to add an option for users to hide certain details from their public profiles. The database is something like:
id username phone email
1 foo1 888-888 a1@b.com
2 foo2 999-999 a2@b.com
3 foo3 111-111 a3@b.com
Now I have 2 options. First is to have another table and use id as the foreign key for referencing. Like
fkeyID disp_phone disp_email
1 0 0
2 0 1
3 1 1
Where 1 is true and 0 is false. Then use SQL join on 2 tables to find whether they want to display their phone/email or not.
2nd Option is: to prefix some flag value like $ in case user wants to forbid public view. Then use a simple php check before displaying or saving preferences. Like:
id username phone email
1 foo1 $888-888 $a1@b.com
2 foo2 $999-999 a2@b.com
3 foo3 111-111 a3@b.com
Please tell which is the better option in terms of space and complexity and why.
Given that
idandfKeyIDare both primary keys an SQLJOINwill be very efficient in the first solution.IMO the first solution is superior to the second since you can perform
SELECTs based on visibility settings in an efficient way (i.e., select only users whose phone numbers are public without considering substrings, e.g.,... WHERE LEFT(phone, 1) != '$'etc.).(This advantage may have no relevance in your case, however.)
And then there was this third possibility:
This will keep data and visibility settings together. It is otherwise identical to the first solution, except you don’t need to
JOIN.