Jump to content

Remove variable substrings from fields


federico07

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/157850-remove-variable-substrings-from-fields/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.