Search code examples
phpmysqlpostfriendprivacy

I need a table for user posts (allowed to see only friend, specific persons etc.)


When user post a message, he can select: allowed to see only friend, specific persons etc..

mysql table:

Post

post_id   post_nr    user_id    privacy option
1         1          2          allowed for friend id1
2         1          2          allowed for friend id2
or
1         1          2          allowed for friends id1,allowed for friend id2 .?

How i can register in mysql multiple options(privacy) for one post? The design of table is ok?


Solution

  • You can solve it by connecting a privacy_option table to your post table.

    post
    
    post_id post_nr user_id
    1       1       2
    
    privacy_option
    
    post_id friend_id
    1       3
    1       4
    

    This way several friends can be listed per post and you can get a list of friend ids with a simple JOIN. Make sure to mark privacy_option.post_id as a foreign key pointing to post.post_id.