xcandiottix Posted July 23, 2010 Share Posted July 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
vichu.1985 Posted July 28, 2010 Share Posted July 28, 2010 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......... Quote Link to comment Share on other sites More sharing options...
xcandiottix Posted July 28, 2010 Author Share Posted July 28, 2010 Yes... I was over complicating it in my head. That's a brilliant idea.. thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.