Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Jose_DIAz's avatar

Update multiple values using a query

this is my mistake

General error: 1366 Incorrect decimal value: '["4.00","3.00"]' for column 'quantity_final' at row 1 (SQL: update `servis` set `quantity_final` = ["4.00","3.00"] where `id` in (1077, 1078))

What I make a query to my two tables and the data that I call in this case is a quantity number for both, the data that is displayed is the one that has the same id for both tables, what I do is that the new quantity is Add to the current amount and I'm done IMAGE: https://i.stack.imgur.com/5RfvB.png

This is my code with which I did it

   foreach($sum_quantity_add as $sum_add){
    $mont1[] = $sum_add->quantity;
    $quantity_actual = Servis::where('id',$id_servis)->get();
    foreach($quantity_actual as $quantity_act){
     $mont2[] = $quantity_act->quantity_final;
     $total = [];
     for($i = 0; $i < count($mont1); $i++) {
        $total[] = $mont1[$i] + $mont2[$i];
     }
  }
}
//DB::table('servicios')->whereIn('id',$id_servicios)->update(['quantity_final' => $total]);        
dd($mont1,$mont2,$total);```

but the problem is when I want to do the update I get the error
0 likes
1 reply
Snapey's avatar

clearly $total is an array. you cannot store an array in a decimal column

Please or to participate in this conversation.