parallax Posted March 16, 2008 Share Posted March 16, 2008 Hi, I have a few questions related to the MySQL (my version is 4.1.20) function Replace. I have a couple of thousand entries in a table, 'descriptions', that are all built on the same html template. But they all have a few html errors which needs to be changed, in other words a small part of a string needs to be replaced in all these records (the string is simple and unique so that is not a problem). As such I figure the best way to go about this is the Replace function in SQL, not any PHP functions such as str_replace, would that be correct? I am not sure wether the standard Replace function such as: UPDATE yourtable SET yourfield = REPLACE(yourfield,"some_string","some_new_string") WHERE yourconditions. would do what I am after? Any advice? Link to comment https://forums.phpfreaks.com/topic/96381-replace-part-of-string-woes/ Share on other sites More sharing options...
Barand Posted March 16, 2008 Share Posted March 16, 2008 Looks OK. If I were going to do something like that on a few thousand records I'd backup the table first, just in case. Link to comment https://forums.phpfreaks.com/topic/96381-replace-part-of-string-woes/#findComment-493300 Share on other sites More sharing options...
parallax Posted March 16, 2008 Author Share Posted March 16, 2008 Yeah that was first on my to-do-list, to backup the database. Also going to run it on a copy of the table first to see if everything went well I am wondering about one thing though. Since the part to be replaced contains html with quotes, how does sql render that in the syntax? For instance: REPLACE(description,"%size="2"%","%size="1"%") Looks kind of odd. Should I maybe use ''? ie. description, 'size="2"', or is it fine as is? Link to comment https://forums.phpfreaks.com/topic/96381-replace-part-of-string-woes/#findComment-493307 Share on other sites More sharing options...
Barand Posted March 16, 2008 Share Posted March 16, 2008 REPLACE(description,'size="2"', 'size="1"') Link to comment https://forums.phpfreaks.com/topic/96381-replace-part-of-string-woes/#findComment-493311 Share on other sites More sharing options...
parallax Posted March 16, 2008 Author Share Posted March 16, 2008 Thanks a lot for the help Barand! I just did a test and it worked, perfect. ;D Link to comment https://forums.phpfreaks.com/topic/96381-replace-part-of-string-woes/#findComment-493315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.