Drupal 7 OR condition with a series of AND condition

Solutions

use db_and

$db_and = db_and();


$qry = db_select('table1', 't1');
$qry->addField('t1','etid','entity_id');
$qry->join('node', 'n FORCE INDEX(field1)', 'n.nid = t1.etid');
$qry->join('table2','t2','n.nid = t2.entity_id');
$qry->join('table3','t3','t3.sid=t2.field2');

$db_and->condition('t3.field', 'yes', '=');
$db_and->condition('n.field', '<value>', 'LIKE');
$db_and->condition('t1.field', '<id>', '=');
$db_and->condition('n.field', '<value>', '=');
$db_and->condition('n.field', <value>, '=');
$db_and->condition('t1.field', '<vlaue>', '=');

$or = db_or();
$or->condition('t1.field', [123,456], 'IN');
$or->condition($db_and);

$qry->condition($or);

$qry->orderBy('t1.field','DESC');
$qry->range(0,300);

Similar questions

Content Type vs. Taxonomy | Example TV Series
As this is my first post here I don't know if I do everything right. Please forgive me. So, my plan is to build a website with many categories and these than contain posts. To explain the stuff in the easiest way I decided to use Series and Episodes. For my use I also want to be able to decide what exactly an episode is. For example is it an normal...
Display paragraphs items in comma-seperated series
I have a series of paragraphs items representing two different types of contributors to a publication: staff (user link) and non-staff (text). (See How to control the display of a user account connected via entity reference) According to Paragraphs preprocess paragraphs handles building the render array for its items in the same way as nodes, comme...
How to show multiple Series of line charts in Views with the Charts module?
I need to create multiple line charts in the same chart. I have a year column, a product column, and a consumer column. I can plot product and year or consumer and year, but when I use all three columns I get a chart that puts both product and consumer data on the same line. I am using the Charts module, with the Highcharts library as its charting ...
How to create an add on chart to overlap 2 data series using the Charts module?
The charts module (for drupal 7) facilitates using the Google Charts API. It is great at taking simple data in a view and displaying a nice chart. I have a problem when trying to display more than one series of data. In my case, I would like to plot two lines on the same graph. This charts module allows for an add on chart that selects a parent cha...
How to set the filter condition by default for specific condition in view
How to set the filter condition by default for specific condition in view i,e i have view with the filter condition STATUS drop down list has 1]live 2] discard,so here i want to filter by default for live status when i open this view can any please tell me how to do this? Thanks a lot in advance.
Nested OR and AND condition with db_select
How can I convert the following query with db_select I am trying with issue is with the "AND" in between where is should be "OR", it is expected I know.how can I change it Output String

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.