Page 1 of 1

more text manipulation

Posted: Wed Jan 21, 2004 2:34 am
by lizlazloz
this is possibly a MySQL question, but possibly not....

idally the first thing i want to do is something like this:

i have an entry in a MySQL table, in a field, which is like this: tim,jim,fred etc... (note this is in one field on 1 row, they are not separate entries/in different fields)

what i want to do is add another name to the end of that list of names... so is this possible?

Code: Select all

update (table) set names=names + ',' + ". $newname ." where id='whatever'
could i do that? and if so is that code correct? or would it have to be done thru php?

next, i want to remove a comma and a name from the list, where $name is now the name to be removed. to do this i am going to have to go thru php right? exploding the entry around the commas, the removing the comma and that name. so, how would i do that, or is it possible through just MySQL, which would probably save a lot of coding, and if so, how?

Posted: Wed Jan 21, 2004 2:54 am
by kettle_drum
Yes you can update your database like that, and then to get the names out, just read the field and explode();

Posted: Wed Jan 21, 2004 5:07 am
by lizlazloz
really? so i could this?

(the names field = bob,jim,ted)

MySQL command:

Code: Select all

update table set names = names-',jim' where id = 1;
and that would make names = bob,ted?

Posted: Wed Jan 21, 2004 7:45 am
by lizlazloz
:bump: :?