So, lets say you have an affiliate link that looks like this:
But you get an email from your affiliate manager telling you to update your links to a new format like this:
MySQL will make that easy.
First, lets check to see how many of our records have that url:
SELECT * FROM table_name WHERE field_name like ‘%http://www.domain.com/aff.php?affid=1234%’
In plain English, that means, select everything from the table named ‘table_name’ where the filed named ‘field_name’ is like the url. The % signs around the url are “wildcards”.
Lets say it returned 189 records. Now lets do our replace
UPDATE table_name SET field_name = REPLACE(field_name, “http://www.domain.com/aff.php?affid=”, “http://affiliates.domain.com/offer/”) WHERE field_name like ‘%http://www.domain.com/aff.php?affid=1234%’
This query is a little more complex, but still pretty straight forward. You should see 189 records updated. You don’t have to use the where clause in this query, but I do simply because it speeds things up and it’s a good habit to always use a where clause unless you really need for your query to look at or check every record. In that query, inside the replace, the first field is the OLD string that you want to replace and the second one is the NEW string you want to replace it with. Just like search and replace using your favorite text editor.
[tags]MySQL, Search, Replace[/tags]