Welcome Guest, Not a member yet? Register   Sign In
Multiple update query
#1

[eluser]snakeblu[/eluser]
Hi everybody,
I have the following code:
Code:
foreach ($data['option'] as $option){
   echo $option['product_option_value'];
   $this->db->query('UPDATE product_option_value SET quantity = (quantity - 1) WHERE product_option_value_id = ' . $option['product_option_value']);
}

The problem is that this code updates only one row even though the array ($data['option']) contains more than one options.

If I add a sleep inside foreach and after the query (for example sleep(3)) the code performs X query, where X is the lenght of array.

It could be a bug?
(sorry for my bad english)

Thanks

Regards
Mauro
#2

[eluser]Mark LaDoux[/eluser]
[quote author="snakeblu" date="1341938754"]
Code:
foreach ($data['option'] as $option){
   echo $option['product_option_value'];
   $this->db->query('UPDATE product_option_value SET quantity = (quantity - 1) WHERE product_option_value_id = ' . $option['product_option_value']);
}
[/quote]

You could try flushing the query cache after every operation like so, let me know if that helps.
Code:
foreach ($data['option'] as $option){
   echo $option['product_option_value'];
   $this->db->query('UPDATE product_option_value SET quantity = (quantity - 1) WHERE product_option_value_id = ' . $option['product_option_value']);
$this->db->flush_cache(); // flush the query from the cache after running it
}




Theme © iAndrew 2016 - Forum software by © MyBB