views:

93

answers:

2

How can i concate this string in mysql

desc=desc+$desct

what i want is each time i insert a variable from PHP that the string is added to the string which was already in db and seperated with ||

the field desc should look like this

desc
10||30||90||710 

say i want to add the value 20

desc
10||30||90||710||20

then the desc field should look like this

How can i implement this?

+5  A: 

Use MySQL CONCAT function:

UPDATE tblName SET colName = CONCAT(colName, "||20") WHERE ...;
Crozin
I will try this thanks
streetparade
Thanks i tryed and it works, have a nice day :-)
streetparade
+3  A: 
$mysql_desct = mysql_real_escape_string($desct, $mysqlconnection);
$query = "
  UPDATE
    tblFoo
  SET
    desc = Concat(desc, '||', '$mysql_desct')
";
mysql_query($query, $mysqlconnection) or die(mysql_error());

see: http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_concat

VolkerK