Search code examples
phpmysqlcodeigniteractiverecordcontinuous-integration

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 :)


Solution

  • 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);