在 codeigniter 中按月在哪里

Where by month in codeigniter

我有这个代码

$where = array('MONTH(c.cashDate)' => 'MONTH(NOW())');
$data['dataCash'] = $this->cash->cashList($where);

但它不起作用,它创建这样的查询

SELECT `c`.`cashId`, `c`.`cashDescription`, `c`.`cashDate`, `c`.`cashCategory`, `a`.`category`, `c`.`cashValue`, `t`.`typeid`, `t`.`type` FROM (`cash` c) LEFT JOIN `cashCategory` a ON `c`.`cashCategory` = `a`.`categoryId` LEFT JOIN `type` t ON `a`.`type` = `t`.`typeid` WHERE MONTH(c.cashDatee) = 'MONTH(NOW())' ORDER BY `c`.`cashDate` desc

当我尝试使用 phpmyadmin 时,它没有一行 但是当我像这样从 MONTH(NOW()) 中删除 ' 时

SELECT `c`.`cashId`, `c`.`cashDescription`, `c`.`cashDate`, `c`.`cashCategory`, `a`.`category`, `c`.`cashValue`, `t`.`typeid`, `t`.`type` FROM (`cash` c) LEFT JOIN `cashCategory` a ON `c`.`cashCategory` = `a`.`categoryId` LEFT JOIN `type` t ON `a`.`type` = `t`.`typeid` WHERE MONTH(c.cashDatee) = MONTH(NOW()) ORDER BY `c`.`cashDate` desc

有效,我如何在控制器中调用 func? 当你这样做时,它不会工作

$where = array('MONTH(c.cashDate)' => MONTH(NOW()));

只需更新您的$where条件

$where = array('MONTH(c.cashDate)' => 'MONTH(NOW())');

进入

$where = 'MONTH(c.cashDate) = MONTH(NOW())';