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