Hello, I’m using Query Builder to create some dynamic queries.
$c = Yii::app()->db->createCommand();
$c->select('id');
$c->from('table');
foreach ($list as $itemId => $itemValues) {
$c->orWhere(['in', 'b', $itemsValues]);
$c->andWhere('a = '.$itemId);
}
So it generates wrong query
where (((b in ['1', '2']) and (a = 5)) or (b in ['5', '8']) and (a = <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />)
Instead, i want to get query
where (b in ['1', '2'] and a = 5) or (b in ['5', '8'] and a = <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' />
How to make that query?
$c = Yii::app()->db->createCommand();
$c->select('id');
$c->from('table');
foreach ($list as $itemId => $itemValues) {
/* $where .= " OR (a = {$itemId} AND b IN (".implode(", ", $itemValues).")) " */
}