Some times we need to append data into a mysql field. So here is solution. Also the query below checks if the value is NULL then if first enters the empty data to the table field.
UPDATE employee SET notes=CONCAT(COALESCE(notes, ''), 'NewDataHere') where employeeID=13;
In the above query concat('','') is to append the new data to the existing data of the field notes. Other function COALESCE(",") checks for NULL, if the field have NULL value then it will enter an empty '' value to field. Other wise in case of NULL value concat() function will end up with a MySQL error.
Hope this will be helpful, comments, suggestions and other coding tricks are most welcome.
Tuesday, April 15, 2008
Subscribe to:
Post Comments (Atom)


1 comments:
dear Khuram,
sorry if the question that i'm about to ask is a bit out of the topic, but hopefully u can help me to solve my problem.
first thing first, i'm doing a PHP-MySQL project for my assignments,
u know, usually the code to retrieve data from mysql is like this (it's just an example):
$result = mysql_query("SELECT email FROM employee WHERE department ='$req_dept'");
while
($row = mysql_fetch_array($result))
{
$item_id = $row['item_id'];
}
intentionally i want to retrieve all the emails stored in "email" field, and display it as a list. however, i realized that the code only retrieve one (1) email out of many, and finally the question is, how do i retrieve all data in a field and display it as a list?
thx for ur time and attention
Post a Comment