Page 1 of 1

Edit a TEXT field

Posted: Wed Aug 20, 2003 11:27 am
by dstefani
Hello all,
I need to edit a comma delimited string in a MySQL TEXT type column.
I want to remove one element of the string.
IE:
column keywords: one, two, three, four, five, six

I want to remove 'four' from the string. // gives: one, two, three, five, six

I thought of doing a 'SELECT keywords FROM products WHERE keyword LIKE %four%'

and then while looping through the resulting recordset use preg_replace()
on each record and then UPDATE that record with the cleaned up string.

Do you know of a more MySQL way of doing this? Some built in function I'm missing?

Thanks,

- D

Posted: Wed Aug 20, 2003 12:05 pm
by McGruff
Overall, I'd do it as you have suggested with some small changes.

"... RLIKE '[[:<:]]" . $value . "[[:>:]]' ..."

.. might be a better option: a LIKE search will return "fourteen" as well as "four".

str_replace is slightly faster than preg_replace

Posted: Wed Aug 20, 2003 1:20 pm
by dstefani
Thanks!