Jump to content

friends list


xcandiottix

Recommended Posts

Say i was going to store a "friends list" for a user. Would it be easier to store the names in a text string in the db instead of having to make a new field for each friend? In other words:

 

001 | Keith | Joe, Jane, Mike

 

or

 

001 | Keith | Joe | Jane | Mike

 

It seems like a pain to make a column for each but since i'm only 6 months into php i haven't really tapped into it's ability to deal with a string of data. My end game would to at some point take the user list and make a selectable table:

 

Friends:

Joe

Jane

Mike

 

Preferably with an array pseudo coded as:

 

Count how many users

for each user

echo username <a href username's page>

 

 

 

Bottom line: Store as Columns or String?

 

p.s. i've reviewed php.net etc. so it's not a matter of not knowing how but more which is preferable

 

Link to comment
https://forums.phpfreaks.com/topic/208624-friends-list/
Share on other sites

Dude,

 

I would say you need to create 1 new table to save friends list. I mean you can save the list as follows

 

id    |  friend

001  | 002

001  | 003

001  | 004

002  | 003

-

-

-

 

Here 002 is ID of Joe

        003 is ID of Jane

        004 is ID of Mike.

 

The reason, later if you want to get all friends of Keith(001), or you need to get the  common friends between Keith(001) and Joe(002), its easy to achieve it by a single query.........

 

Link to comment
https://forums.phpfreaks.com/topic/208624-friends-list/#findComment-1092042
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.