[eluser]ppwalks[/eluser]
Hi all,I'm trying to use CL native batch update function, but for the purpose I am trying it does not like it. I am trying to update where product_id = product_id, it is in a joining table so it can occur several times.
Here's my array:
Code:
Array ( [0] => Array ( [product_id] => 327 [category_id] => 3 ) [1] => Array ( [product_id] => 327 [category_id] => 5 ) [2] => Array ( [product_id] => 327 [category_id] => 7 ) )
The error code says:
Error Number: 1062
Duplicate entry '327-3' for key 'PRIMARY'
Code:
UPDATE `product_category` SET `category_id` = CASE WHEN `product_id` = '327' THEN '3' WHEN `product_id` = '327' THEN '5' WHEN `product_id` = '327' THEN '7' ELSE `category_id` END WHERE `product_id` IN ('327','327','327')
And my model:
Code:
function update_product_cat($product, $cat_id) {
$data = array();
foreach( $product as $index => $value )
{
$data[] = array(
'product_id' => $value ,
'category_id' => $cat_id[ $index ]
);
}
$this->db->update_batch('product_category', $data, 'product_id');
Why will it not update the table, I have already double checked and both columns are (int) which is correct?
Any help to point me in the right direction would be greatly appreciated.
Thanks
}