Blog Details

concate field data using update query in php mysql

                                    <strong>UPDATE tableName SET fieldName = CONCAT(fieldName, 'New Data To Add Here') WHERE ...</strong>
<p style="text-align: left;"><em>example :</em></p>
     <strong>UPDATE ws_contact SET webpage = CONCAT(webpage, '') WHERE id=1</strong>

But this query will not work if the field is NULL (which makes sense as there is nothing to append),  you can use below query to solve NULL problem

<strong>UPDATE <strong>tableName</strong> SET field = CONCAT(COALESCE(field, ''), 'New Data') WHERE ...</strong>

<em>example :</em>

<strong>     UPDATE ws_contact SET webpage = CONCAT(COALESCE(webpage, ''), '') WHERE id=1</strong>

Basically this check whether the field is NULL or not. If it's NULL then it will automatically use blank data for the field otherwise it'll default to the field's value. Then, it will do the concatenation of the new data.
<div> You could also use IFNULL() instead of COALESCE()</div>


Php mysql

Latest posts

Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t


<ol> <li><a href="

Creating Model

<ol> <li><a href="

Get Free Quote