具有一系列 AND 条件的 Drupal 7 OR 条件
Drupal 7 OR condition with a series of AND condition
我有一个如下所示的 `Drupal 查询
$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');
$qry->condition('t3.field', 'yes', '=');
$qry->condition('n.field', '<value>', 'LIKE');
$qry->condition('t1.field', '<id>', '=');
$qry->condition('n.field', '<value>', '=');
$qry->condition('n.field', <value>, '=');
$qry->condition('t1.field', '<vlaue>', '=');
$qry->orderBy('t1.field','DESC');
$qry->range(0,300);
我想为此查询添加一个 OR
条件。所以这将是一个全局 OR
条件。
我添加了如下代码
$or = db_or();
$or->condition('t1.field', [123,456], 'IN');
$qry->condition($or);
但它没有添加 OR
条件,而是将条件查询放在 AND
条件的大括号内。
如何实现像
这样的输出查询
where field = value and field = value and field = value OR field = value
通过使用 Drupal 查询生成器?请帮忙
使用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);
我有一个如下所示的 `Drupal 查询
$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');
$qry->condition('t3.field', 'yes', '=');
$qry->condition('n.field', '<value>', 'LIKE');
$qry->condition('t1.field', '<id>', '=');
$qry->condition('n.field', '<value>', '=');
$qry->condition('n.field', <value>, '=');
$qry->condition('t1.field', '<vlaue>', '=');
$qry->orderBy('t1.field','DESC');
$qry->range(0,300);
我想为此查询添加一个 OR
条件。所以这将是一个全局 OR
条件。
我添加了如下代码
$or = db_or();
$or->condition('t1.field', [123,456], 'IN');
$qry->condition($or);
但它没有添加 OR
条件,而是将条件查询放在 AND
条件的大括号内。
如何实现像
这样的输出查询where field = value and field = value and field = value OR field = value
通过使用 Drupal 查询生成器?请帮忙
使用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);