Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: phranque

Message Too Old, No Replies

Can You Use A Find & Replace Command

My SQL Gurus Wanted

     
9:51 pm on Aug 13, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Jan 21, 2003
posts:226
votes: 0


Hi All

I have a full text field that is in a particular table. Does anyone know if there is a way to run a find and replace command on this field.

For info the field is lots of html text, and the text I want to change is a particular URL within this text.

Any syntax code would be greatly appreciated.

Thanks

PS I have PHPMyAdmin nothing else to connect.

11:45 pm on Aug 13, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:236
votes: 0


You can do a find/replace in one statement in MySQL, but it is for whole values (as far as I know).

Ex.

UPDATE table SET field1='somethingelse' WHERE field1='something';

As far as replacing just a portion of text with the field, I'm not sure if that is possible in MySQL or not. However, it would be very easy to do with a very short php or perl script.

12:07 am on Aug 14, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Jan 21, 2003
posts:226
votes: 0


Could you possibly give me an example of the script you mean.

thanks

12:14 am on Aug 14, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 16, 2003
posts:593
votes: 0


Ha!

I was just trying to do this today... but I dont know jack about mysql

1:34 am on Aug 14, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 2, 2003
posts:515
votes: 0


#1- Always make a back-up before doing stuff like this

The manual is your friend..
[google.ca...]

Gave me the following:
[dev.mysql.com...]

Which highlights this useful function:
REPLACE(str,from_str,to_str)

So... the following should replace all instances of "foo" in your string with "bar":
UPDATE table SET field1=REPLACE(field1, 'foo','bar')

Hmm... it's a friday night and I'm making stupid programmer foobar jokes... gotta get out!

11:23 am on Aug 14, 2004 (gmt 0)

Full Member

10+ Year Member

joined:Jan 21, 2003
posts:226
votes: 0


All Fixed :)using

UPDATE table_1 SET `fulltext` = REPLACE(`fulltext`, "a", "b")