假如表名为user,表如下
id | devid |
1 | 1,2,3,12,13,14 |
要删除表user的devid字段中的1的值,注意12,13,13是不能删除。
php语法如下:
$delnum = 1;
$id =1;
$sql = "update user set devid = trim(both ',' from replace(concat(',', devid, ','), ',$delnum,', ',')) where id = '$id'"; if ($con->exec($sql)) { echo 1; }
sql语法如下:
update `user` set devid = trim(both ',' from replace(concat(',', devid, ','), ',1,', ','))