more text manipulation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

more text manipulation

Post 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?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Yes you can update your database like that, and then to get the names out, just read the field and explode();
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

Post 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?
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

Post by lizlazloz »

:bump: :?
Post Reply