IF语句在哪里(codeigniter活动记录)

问题描述 投票:3回答:2

我想询问有关活动记录的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'

当我尝试在活动记录上实现时,没有显示任何内容。

感谢帮助 :)

php mysql codeigniter activerecord continuous-integration
2个回答
1
投票

来自Codeigniter Userguide

$ this-> db-> where()接受可选的第三个参数。如果将其设置为FALSE,CodeIgniter将不会尝试使用反引号来保护您的字段或表名称。

$this->db->where("IF((month(a.create_date)) < month(now()) , d.approve_by, '') like $username", NULL, FALSE);


0
投票
           $this->db->select('
            (CASE 
            WHEN orderdetails.ProductID = 0 THEN dealmaster.deal_name
            WHEN orderdetails.DealID = 0 THEN products.name
            END) 
            as product_name')
© www.soinside.com 2019 - 2024. All rights reserved.