[英]IF statement on where(codeigniter active record)
我想詢問有關活動記錄的codeigniter是否可以在活動記錄中使用IF語句?
$this->db->where("IF((month(a.create_date)) < month(now()) , d.approve_by, '') like $username" );
所以,我想獲得數據approve_by但create_date必須是當月之前的月份
我試過mysql,它可以。
IF(month(a.create_date) < month(NOW()),b.approve_by,'') = 'someusername'
當我嘗試在活動記錄上實現時,沒有顯示任何內容。
感謝幫助 :)
$ this-> db-> where()接受可選的第三個參數。 如果將其設置為FALSE,CodeIgniter將不會嘗試使用反引號來保護您的字段或表名稱。
$this->db->where("IF((month(a.create_date)) < month(now()) , d.approve_by, '') like $username", NULL, FALSE);
$this->db->select('
(CASE
WHEN orderdetails.ProductID = 0 THEN dealmaster.deal_name
WHEN orderdetails.DealID = 0 THEN products.name
END)
as product_name')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.