Welcome Guest, Not a member yet? Register   Sign In
Issue with updateBatch method
#1

(This post was last modified: 10-30-2023, 11:38 AM by ozornick. Edit Reason: Reformat code )

Hi,
I have a DB table named 'products'. It has the following columns:  id, stock_shipped, stock_on_hand
I am facing some issues in using the updateBatch method.
When an order is placed, the stock should update properly for all the items/products in the order.
So I need to increase/decrease the existing value in DB table columns: stock_shipped and stock_on_hand

Code:

PHP Code:
$data[0]['id'] = 100;
$data[0]['stock_shipped'] = stock_shipped 10;
$data[0]['stock_on_hand'] = stock_on_hand 10;

$data[1]['id'] = 101;
$data[1]['stock_shipped'] = stock_shipped 25;
$data[1]['stock_on_hand'] = stock_on_hand 25;
...
...
...


$builder $this->db->table('products');
$builder->updateBatch($data'id'); 


Can you please suggest a way to use the same method: updateBatch correctly?
Reply
#2

Can you carefully read here please https://codeigniter.com/user_guide/datab...pdatebatch
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#3

I read the documentation. Nothing was mentioned about the existing value. 
How can I add/subtract from, the current value of a database column when I use the data array?
Reply
#4

(10-31-2023, 12:41 AM)ashlythomas Wrote: How can I add/subtract from, the current value of a database column when I use the data array?

I'm not sure it works, but try to use RawSql.
See https://codeigniter.com/user_guide/datab...der-insert
Reply




Theme © iAndrew 2016 - Forum software by © MyBB