Find and replace in mysql?

Status
Not open for further replies.

abhorrent

New member
Feb 6, 2008
783
13
0
Illinois
I'm kind of a noob with mysql but I would like to do something.
I have this upload script that I've been using and everything has been fine until now. I uploaded 150 posts and something went wrong.

Where there was supposed to be a "non-breaking space" I got a question mark instead. Now, if I have too I will, but I'd rather not have to edit them all manually. When I look at the entries in the table there's no "?", just a space. If I edit it with a nbsp it works fine. so something happened with my upload script.

After googling around I found this...
Code:
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
So if I change the code to this, will it work?
Code:
update [wp_posts] set [post_content] = replace([post_content],'[?]','[ ]');
I'm not even really sure how I go about running this in phpmyadmin. I can go in and do a single record but have never really done anything on a mass scale. It's something I could live with if I have too but I'm kind of anal so it will bug me for ever if I don't fix it.

Any guidance would be appreciated.
Thanks -- Jon
 


Hey abhorrent,

In the update query, there's no need to use the brackets.

The 2nd statement (without brackets) looks good to me. To execute the statement, just go to the "SQL" tab in phpMyAdmin (with the target database selected) and paste in your SQL statement.

This should work fine pasted in:
UPDATE wp_posts SET post_content = REPLACE(post_content,'?',' ]')
 
  • Like
Reactions: abhorrent
Hey abhorrent,

In the update query, there's no need to use the brackets.

The 2nd statement (without brackets) looks good to me. To execute the statement, just go to the "SQL" tab in phpMyAdmin (with the target database selected) and paste in your SQL statement.

This should work fine pasted in:
UPDATE wp_posts SET post_content = REPLACE(post_content,'?',' ')
That worked... kind of.
now I have this.. �YES
What the hell is � ? Looking in the field all I see is an empty space. It doesn't seem to like   for some reason.

I gues I can manually edit them in the table. It will still be faster then doing it in WP.
 
I'm not 1000% for sure but I have see this before. Basically, what I think it is, is a blank character in a different character set. That is if the current character set the browser is using doesn't have that value then it will display a � because it doesn't know what else to do. In essence it's a renegade character that has to be replaced with a traditional space.

Try running a: REPLACE(post_content,'�',' ')
 
Status
Not open for further replies.