-1

This is the code that I have made so far.

 $query->where[1]['conditions'][]=array(
            'field'=> $payment_field,
            'value' => 16184,
            'operator' => '=',
        );
        $query->where[1]['conditions'][] = array(
            'field' => $covered_region,
            'value' => $region_id,
            'operator' => '='

        );
 $query->where[1]['conditions'][]=array(
            'field'=> $payment_field,
            'value' => 16185,
            'operator' => '=',
        );
        $query->where[1]['conditions'][] = array(
            'field' => $covered_region,
            'value' => $region_id,
            'operator' => '=',
        );

How can I group the following and do as the query below?

    AND (
     ((field_data_field_home_care_payment_plan.field_home_care_payment_plan_tid ='16184')AND (field_data_field_covered_regions.field_covered_regions_tid IN  ('65'))) 
OR   ((field_data_field_home_care_payment_plan.field_home_care_payment_plan_tid ='16185')AND (field_data_field_covered_regions.field_covered_regions_tid IN  ('65'))) 
)
1

Any particular reason you're manually adding to the where array rather than using the add_where function?

I believe you should be able to do something like this:

$db_and_1 = db_and()
  ->condition($payment_field, 16184)
  ->condition($covered_region, $region_id);

$db_and_2 = db_and()
  ->condition($payment_field, 16185)
  ->condition($covered_region, $region_id);

$query->add_where(1, db_or()
  ->condition($db_and_1)
  ->condition($db_and_2)
);

The important part is the db_or function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.