![](/img/trans.png)
[英]Codeigniter 2.2 - Active Record update with left join and multiple where clauses
[英]CodeIgniter Active Record multiple WHERE clauses
我正在嘗試轉換此查詢:
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();
但這並沒有產生預期的效果。 它似乎沒有將括號放在第二組條件周圍,這導致查詢無法按預期工作。 我還能怎么做才能代表我想要的?
謝謝您的幫助!
您可以使用
$this->db->select('*');
$this->db->from('table');
$this->db->where('condition1 =',' condition');
$where = '(date1 = "date" OR renewal1 = "renewal")';// you can use your condition like this
$this->db->where($where);
$q = $this->db->get();
$results = $q->result();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.