我想问一下活动记录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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句