I have a query, which I have to run in a foreach cycle.
I run the query with db_query() function.
My code looks similar to this one (of course, this is just an example code with example values):
$query = '
UPDATE mytable SET some_fields = "%s"
WHERE
some_fields = "%s"AND
other_field = "%s" AND
another_field = "%s"
';
foreach($blabla as $index => $value){
$prev_value = 'these variables are set in the meantime too...';
$other_field_value = 'blabla';
$another_field_value = 'blablabla';
if($this_is_my_condition){
$query_result = db_query( $query,
$value,
$prev_value,
$other_field_value,
$another_field_value
);
$affected_rows = db_affected_rows();
if( empty($query_result) or empty($affected_rows) ){
$unsuccessful_queries[] = 'blablabla '.$index.', '.$value;
}
}
}
if(!empty($unsuccessful_queries)){
$errorMsg = NULL;
foreach($unsuccessful_queries as $index => $value){
$errorMsg .= 'Setting '.$value.' parameter was unsuccessful!<br />'."\n";
}
throw new ParameterSettingException($errorMsg);
}
In theory, my query is OK, because it works for just one query perfectly with the same values (if it has to be run depending on my condition ( in the example above, $this_is_my_condition ) ), BUT it doesn't work for multiple queries, the rest of the queries are getting simply ignored: my $unsuccessful_queries array is full of the other to-be-updated stuffs that would have to be executed.
The values are correct (that's for sure, because these work with the same values, but with just ONE query!!).
What can be the source of the problem? Why can I run only ONE query, why are the others getting ignored?
Thanks in advance!