php: more the one in a field
- lithium
-
lithium
- Member since: Dec. 16, 2004
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
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.
-
- Send Private Message
- Browse All Posts (13,458)
- Block
-
- Forum Stats
- Moderator
- Level 44
- Game Developer
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
- lithium
-
lithium
- Member since: Dec. 16, 2004
- Offline.
-
- Forum Stats
- Member
- Level 09
- Blank Slate
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
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
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
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.


