Concatenate field value in replace() mysql

Discuss coding issues, and scripts related to PHP and MySQL.
Marius
Posts: 107

Concatenate field value in replace() mysql

Hello,
How can I concatenate the value of a string in the replace() statement in mysql?

For example, in the 'content' column i have something like this:

Code: Select all

some content... {{$name_val}}
other text...
- The "name_val" is the value of the field 'name' in the same table.
I want to delete /replace all the '{{$name_val}}' sub-string from content, so, I need to apply Update with replace() statement with the value of the 'name' column.
But, how to add the value of the 'name' column in replace()?

Admin Posts: 805
Hi,
You can use the concat() function in the replace() statement.

Code: Select all

REPLACE(col_name, concat('string',  col_2, 'join-string'), 'new_value')
- Here is an example:

Code: Select all

UPDATE table_name SET content = REPLACE(content, concat('{{$',  col_name, '}}'), 'new_value') WHERE id < 100