Jump to content

Recommended Posts

before now, i had my site set up so a new member got a table assigned to him/her for friends and block list,  i was told this was a bad idea as it would result in too many tables.

 

this is the layout of the tables which where created:

 

friend_id      |  accepted  |  blocked  |  date

-----------------------------------------------------------------

friendID01  |  1              |  0            |  1270923292

-----------------------------------------------------------------

friendID02  | 0              |  1            |  1269465333

 

(date being the date they where accepted or blocked)

 

 

would this be a better way of laying out a table which has friend/block data for all users...

 

member_id | acceptedFriends                        |  blocked

---------------------------------------------------------------------------------------------------

member01  | friendID01(1270923292); frie.....|  friendID02(1269465333);

---------------------------------------------------------------------------------------------------

member02  | friendID01(1272542525); frie.....| 

 

 

sorry for the rather crap representation, but what im trying to show is all accepted friends of a member would be added to a single 'acceptedFriends' column, each separated via a ';'  with the time stamp within brackets.  (and same thing for blocked)

 

 

would this be a good way for the data to be stored?

 

please do say if you can think of anything better (:

thanks guys

Link to comment
https://forums.phpfreaks.com/topic/200606-a-better-way/
Share on other sites

No.  You don't store multiple values in a single "cell" as delimited strings.

 

Table: member

Columns: id | name | ...

 

Table: member_friends

Columns: id | member_id | friend_id

 

Table member_blocked_members

Columns: id | member_id | blocked_member_id

 

EXAMPLE:

Table: member

Columns: id | name | ...

3, Jerry

4, Bob

5, Larry

6, Sally

 

Table: member_friends

Columns: id | member_id | friend_id

1, 3, 4    -- Jerry is friends with Bob

2, 3, 6    -- Jerry is friends with Sally

3, 5, 6    -- Larry is friends with Sally

 

Table member_blocked_members

Columns: id | member_id | blocked_member_id

1, 4, 5    -- Bob has blocked Larry

2, 6, 5    -- Sally has blocked Larry

Link to comment
https://forums.phpfreaks.com/topic/200606-a-better-way/#findComment-1052696
Share on other sites

Just remember that Bob and be friends with Sally while at the same time Sally is blocking Bob.

 

You will probably want to honor "block" requests over "friend" requests when displaying information.  You can accomplish this with UNION EXCEPT or sub-queries.

Link to comment
https://forums.phpfreaks.com/topic/200606-a-better-way/#findComment-1052720
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.