federico07 Posted May 12, 2009 Share Posted May 12, 2009 Hello, I have a table as follows: idProductBrand 1Pepsi prod1Pepsi 2Fanta prod2Fanta 3Coke prod3Coke I need to remove the Brand prepended to the text included in Product column. I need to get: idProductBrand 1prod1Pepsi 2prod2Fanta 3prod3Coke I tried the following query: mysql_query("UPDATE table SET Product=REPLACE(Product, '$Brand', '')") or die(mysql_error()); but it does not work (it replaces only in the last row). Is correct when placing a variable ($Brand) in the text to be replaced? Does anybody know any UPDATE commands working on that? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/157850-remove-variable-substrings-from-fields/ Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 That's close. Try this - UPDATE table SET Product = REPLACE(Product, Brand, ''); Quote Link to comment https://forums.phpfreaks.com/topic/157850-remove-variable-substrings-from-fields/#findComment-832595 Share on other sites More sharing options...
federico07 Posted May 12, 2009 Author Share Posted May 12, 2009 Now it works perfectly. Ken2k7, thanks for your advice ! Quote Link to comment https://forums.phpfreaks.com/topic/157850-remove-variable-substrings-from-fields/#findComment-832627 Share on other sites More sharing options...
fenway Posted May 12, 2009 Share Posted May 12, 2009 You might want to TRIM() that, too. Quote Link to comment https://forums.phpfreaks.com/topic/157850-remove-variable-substrings-from-fields/#findComment-832632 Share on other sites More sharing options...
federico07 Posted May 13, 2009 Author Share Posted May 13, 2009 It seems only case sensitive. Any way to get it working with a case insensitive search/replace? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/157850-remove-variable-substrings-from-fields/#findComment-833072 Share on other sites More sharing options...
fenway Posted May 13, 2009 Share Posted May 13, 2009 Just UPPER() each part of the replace. Quote Link to comment https://forums.phpfreaks.com/topic/157850-remove-variable-substrings-from-fields/#findComment-833232 Share on other sites More sharing options...
federico07 Posted May 14, 2009 Author Share Posted May 14, 2009 Thanks. I tried this: UPDATE table SET Product=REPLACE(Product, (UPPER(Brand)), ''); However the problem is the text I need eliminating -- referred to the example above -- could be in format PEPSI, pepsi, Pepsi. So I would need something 'universal' doing the job. Quote Link to comment https://forums.phpfreaks.com/topic/157850-remove-variable-substrings-from-fields/#findComment-833687 Share on other sites More sharing options...
fenway Posted May 14, 2009 Share Posted May 14, 2009 You didn't upper() product. Quote Link to comment https://forums.phpfreaks.com/topic/157850-remove-variable-substrings-from-fields/#findComment-834348 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.