Forum Moderators: open

Message Too Old, No Replies

Search and Replace MYSQL DB

doesn't work for me

         

CodilX

4:05 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



Hi everyone,

I'm having trouble with this little script here..

I have a referer db, and basicly I'm tired of seeing so many versions and subversions of the same browsers, that it really ticks me of.

So:

I'm trying to replace all instances of lets say Firefox 1.***.. to Firefox 1. Lets say instead of Opera 9.21 - just Opera 9.

So here's what I tried:

UPDATE visitors SET browser = replace( browser, 'Firefox 1.', 'Firefox 1' );

The problem is, that it doesn't change the entire string. It just changes the 'Firefox 1.' to 'Firefox 1', but leaving all the other numbers and dots unchanged.

Is there a PHP or MySQL way to make a change to the entire cell?

Demaestro

6:32 pm on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would try using wildcard

So

UPDATE visitors SET browser = 'Firefox 1' where browser like 'Firefox 1.%'

The % is a wildcard so it has to start with 'Firefox 1.' but it can be anything after the .

Before you execute it though do a select to make sure it is return all the rows you would want to change. Just to be safe.

So

select browser from visitors where browser like 'Firefox 1.%'

CodilX

11:10 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



wow thx a bunch!