Be a Supporter!

php: more the one in a field

  • 300 Views
  • 5 Replies
New Topic Respond to this Topic
lithium
lithium
  • Member since: Dec. 16, 2004
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
php: more the one in a field 2006-11-13 03:36:15 Reply

okay, i have a database with fields ID, USER and FRIENDS. the FRIENDS field has values like john,tom,mark,ben. i need a php code with which i could extract these seperatly and be able to delete or add friends. can you help me plz? :)

Afro-Ninja
Afro-Ninja
  • Member since: Mar. 2, 2002
  • Offline.
Forum Stats
Moderator
Level 44
Game Developer
Response to php: more the one in a field 2006-11-13 04:12:28 Reply

ok first of all, do you know how to extract data regularly? If so then all you have to do is select from the friends field then do

$names = explode(',',$datafromfield);

that will separate all the friends into the array, so $names[0], $names[1], etc will each give you a name. If you want to add a friend you can simply add it onto the end by doing

array_push($names,'Phil');

then implode it back into a string and update the database with it

$datatoinsert = implode(",",$names);

However this really isn't the best method to do it, I would suggest setting up an additional table to resolve the friends to friends relationship.... What exactly do you need to accomplish with this? I'm afraid there isn't a simple 'php code' that will do all of this for you


BBS Signature
lithium
lithium
  • Member since: Dec. 16, 2004
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to php: more the one in a field 2006-11-13 05:19:48 Reply

this helped, thanx :) but i still don't get how can i delete one of the friends. lets say i've made a table
| $name[0] | click to delete
| $name[1] | click to delete
| $name[2] | click to delete
etc. how to make it work?

henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to php: more the one in a field 2006-11-13 06:07:58 Reply

You want another table, you are storaging mutiple values in one field.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

lithium
lithium
  • Member since: Dec. 16, 2004
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to php: more the one in a field 2006-11-13 06:12:08 Reply

in that case i would need to give every user his own table, it would be much easyerto put these in one field

henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to php: more the one in a field 2006-11-13 11:53:16 Reply

No, you would not have to give each user his own table, just fake it.
Add a field that specifies for who the record is.
So you will have sender and reciver.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.