"mysql - delete value in the row, instead of deleting the row" Code Answer

2

you can try this -

update users set eat = replace(eat, 'banana', '') where eat like '%banana%';

this would replace only banana from eat column where it is present.

update

loop through the data and replace those values. this might help -

$check_val = 'banana';

//select those rows first
"select id, eat from users where eat like '%" . $check_val . "%'"

foreach($data as $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'] . "' where eat like '%" . $check_val . "%'"
}
By Michael Kennedy on July 13 2022

Answers related to “mysql - delete value in the row, instead of deleting the row”

Only authorized users can answer the Search term. Please sign in first, or register a free account.