Reputation: 27
In my table I have some rows with same 'stock_id', and need update with 2 conditions, but don't work, just update all rows with value 1
$this->db->query('UPDATE stock_table SET size = IF(kit = \'n\', 1, (1 * 10)) WHERE id = '.$row->stock_id);
But my size have S - M - X with same stock_id
Eg: I need update qtde column where stock = 13 and size = S
Upvotes: 0
Views: 226
Reputation: 780724
Add the other condition with AND
in the WHERE
clause.
$this->db->query('UPDATE stock_table SET qtde = IF(kit = \'n\', 1, (1 * 10)) WHERE size = \'S\' AND id = '.$row->stock_id);
BTW, if $row
is the result of another query, you can use UPDATE + JOIN
to do this in one query, instead of looping. See MySQL update table based on another tables value
Upvotes: 1