Please correct me if I'm wrong, I am trying to update multiple rows, incrementing its value, from what I know, it is impossible to do this using update_batch() as CI always escape the value when using update_batch(), is this correct, or if there is a way, please elaborate the way as an answer. For example, I have this array:
$array = array(
array(
'product_id' => '1',
'value' => '5',
),
array(
'product_id' => '2',
'value' => '15'
)
);
Now I want to update my table by incrementing column value(INT) by the value in the array where column product_id = product_id in the array.
What I'm doing now is using loops of set like this
foreach($array as $a) {
$this->db->set('value' + $a['value'], FALSE);
$this->db->where('product_id', $a['product_id'];
$this->db->update('table');
}
However sometimes I will need to update more than 10 rows, and I'm thinking this process will be costly and take a lot of memory, how do i further simplify this method to get the same result ?
All answers are greatly welcome and appreciated. Thank you in advance.
You can use $this->db->update_batch();
to update multiple record at once. See this codeigniter user guide for update query.