php - MySQL - Delete value in the row, instead of deleting the row -
i want delete searched value (not row) if row contains searched value. example, if want remove banana, should remove banana rows contain banana.
tried this,
delete users eat '%banana%'
however, removes rows. how can remove search value rows ?
you can try -
update users set eat = replace(eat, 'banana', '') eat '%banana%';
this replace banana
eat
column present.
update
loop through data , replace values. might -
$check_val = 'banana'; //select rows first "select id, eat users eat '%" . $check_val . "%'" foreach($data $v) { $temp= explode(',', $v['eat']); $temp= array_map(function($t) use($check_val) { return (strpos($t, $check_val) !== false) ? null : $t; }, $temp); $temp = array_filter($temp); $v['eat']= implode(',', $temp); "update users set eat= '" . $v['eat'] . "' eat '%" . $check_val . "%'" }
Comments
Post a Comment