A specific row in MYSQL

How can I account for this line in mysql

desc=desc+$desct

what i want, every time i insert a variable from php that the string is added to the string that was already in db and split by ||

the desc field should look like this:

desc
10||30||90||710 

let's say i want to add a value of 20

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

then the desc field should look like this:

0
source share
2 answers

Use MySQL CONCAT :

UPDATE tblName SET colName = CONCAT(colName, "||20") WHERE ...;
+6
source
$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

+4
source

Source: https://habr.com/ru/post/1737671/


All Articles