简体   繁体   中英

IF statement on where(codeigniter active record)

i wanna ask about active record codeigniter is it possible to use IF statement in where active record?

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

So, i want to get data approve_by but the create_date must be month before current month

i have try with mysql, and it can.

IF(month(a.create_date) < month(NOW()),b.approve_by,'') = 'someusername'

when i try to implement on active record, that not showing anything.

Thanks for help :)

from the Codeigniter Userguide

$this->db->where() accepts an optional third parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks.

$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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM