Welcome to WebmasterWorld Guest from 23.20.223.88

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

find and replace text with where statement

     
1:27 am on Aug 29, 2011 (gmt 0)

5+ Year Member



Hiya,

I am trying to find and replace text in my db with mysql. I think the code is correct but it is not replacing any text? Offer any suggestions?

UPDATE db SET field= replace(field,'<script type="text/javascript">// <![CDATA[
google_ad_client = "pub-number";
/* 336x280, created 12/24/10 */
google_ad_slot = "number";
google_ad_width = 336;
google_ad_height = 280;
// ]]></script>
<script src="webpage" type="text/javascript">
</script>','<br />') Where field like 'Song%';


Any help would be appreciated.

Best regards,
Matt
6:21 pm on Aug 29, 2011 (gmt 0)

10+ Year Member



First, using phpMyAdmin or the mysql command line, try the query:

SELECT * FROM db WHERE field LIKE 'Song%';


This will show you the records that the query will update. If it doesn't return any records, then the table name, field name, or value to find is wrong.

Assuming the above works, I suspect you're running into a problem with the replacement string not exactly matching what is in the databases. It's going to be difficult to handle because of the embedded line feeds and, possibly, embedded spaces that aren't obvious.

You could do something like:

UPDATE db SET field=REPLACE('src="webpage"', 'id="webpage"', field) WHERE field LIKE 'Song%';


The above won't remove the Adsense code, but will make it inert.

-- Roger
1:22 am on Aug 30, 2011 (gmt 0)

5+ Year Member



thanks roger. I will check it out.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month