batch update on primary key? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: batch update on primary key? (/showthread.php?tid=54115) |
batch update on primary key? - El Forum - 08-23-2012 [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) { 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 } batch update on primary key? - El Forum - 08-23-2012 [eluser]ppwalks[/eluser] Solved, and it was so obvious as well, I simply deleted the records then inserted the updated one with the same function I used for the original insert... Thanks anyway |