我想选择记录,但是当我使用or_where时,请不要遵循我的需要:
对于黄线,我不需要,但它也会出现。让我们看看我的代码
$this->db->select('*')
->from('tblDiscountType')
->where('ShopLocationID', 4)
->or_where('ShopLocationID', NULL)
->where('DiscountApplicableId', 1)
->where('CountryID', 7)
->where('Current', -1);
return $this->db->get();
如果您这样做$this->db->last_query();
,则可以看到生成的查询。
实际上,它的作用类似于
SELECT * FROM tblDiscountType
WHERE ShopLocationID = 4 OR ShopLocationID IS NULL
AND DiscountApplicableId = 1 AND ...
你想要的是 WHERE (ShopLocationID = 4 OR ShopLocationID IS NULL) AND DiscountApplicableId = 1 AND ...
Active Record不适用于复杂的查询。因此,可以直接使用编写查询,$this->db->query($your_query)
也可以欺骗活动记录,如下所示:
$this->db->where("(ShopLocationID = 4 OR ShopLocationID IS NULL) AND DiscountApplicableId = 1 AND ...", NULL, FALSE);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句