CodeIgniter Active记录多个WHERE子句

时间:2015-06-30 14:25:23

标签: php mysql codeigniter activerecord

我正在尝试转换此查询:

 SELECT * FROM table WHERE condition1 = 'example' AND (date1 = 'date' OR renewal1 = 'renewal');

进入CodeIgniter的Active Record格式。我尝试了以下方法:

$q = $this->db->select('*');
$q = $this->db->from('table');
$q = $this->db->where('condition1 = condition');
$q = $this->db->where('date1 = date OR renewal = renewal');
$q = $this->db->get();
$results = $q->result();

但这并没有产生预期的效果。它似乎没有将括号放在第二组条件周围,这导致查询无法按预期工作。我怎么能这样做才能代表我想要的东西?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您可以使用

January|    February |  March|  QFY   | SALES_GROUP |SALESPERSON_NUMBER    
109.34 |    13.42   |  359.41|  482.17|  A          | 6607
99.52  |    95.62   |  89.63 |  284.77|  A          | 6608    
340.95 |    652.25  |  352.26|  1345.46| B          | 8888