public function addToTransfer($data)
{
$countProductsAdded = $this->where('product_id', $data['product_id'])
->where('product_transfer_id', $data['product_transfer_id'])
->where('transfer_id', $data['transfer_id'])
->countAllResults();
for($i = $countProductsAdded; $i < $data['quantity']; $i++) {
$dataToUpdate = [
'transfer_id' => $data['transfer_id'],
'product_transfer_id' => $data['product_transfer_id'],
'status' => $data['status'],
'warehouse' => $data['new_warehouse']
];
$response = $this->set($dataToUpdate)
->where('product_id', $data['product_id'])
->where('status', 'instock')
->where('warehouse', $data['old_warehouse'])
->update();
}
return $response;
}
Hello, i have a problem with this loop, i don't understand what could be wrong here is a black box for now and i don't understand what's wrong.
I will explain what i checked.
- $countProductsAdded - returned correctly (it's counting already added results from database)
- $data['quantity'] - returned correctly (how many times i want to run that loop)
What i expect, i call this loop with quantity = 5, i expect to run 5 times and update 5 rows from database which meets some criterias.
what i get, totally different :)), is update all rows from database which meets those criterias.
It's not understandable for me because same loop, same logic is working for an insert call
BTW, it's php, codeigniter 4