I'm working on some sort of social network these days, and I'm wondering how I can store the user connections in a database.
The structure I've been thinking of looks like this, and it suits me pretty good. I guess it's against the third rule of DB-normalization, but I don't see a better way to store the connections since there will be a big amount of users (hopefully ;) ) and it doesn't make sense to create a new column for every new connection.
table-name: tbl_users
user_id username connected_users
---------------- ---------------- --------------------
1 Freak 2,4
2 Banana 1,3,5
3 MacKing 1,2,4,5
4 Nightmare
5 Dreamer 2,3
... ... ...
What I'm looking for is:
- a way to add and/or delete single values from the 'connected_users' column (for example when a user is on another user's profile and clicks the button 'connect-with' or 'delete-connection')
and to find connections, for example when a user writes a post (button 'new-post'), to find all the authors current connections and save them to my other table: 'tbl_blogposts' (seems strange, but I want those current connections to be stored within the post and never be changed again, no matter whom the author is connected to, later):
table-name: tbl_blogposts
post_id author connected_users
---------------- ---------------- --------------------
1 1 2,4
2 3 1,2,4,5
3 3 1,2,4,5
4 5 2,3
5 2 1,3,5
... ... ...
or
- a better way to store all these connections