我有这段代码
$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()));
答案 0 :(得分:0)
只需更新$where
条件
$where = array('MONTH(c.cashDate)' => 'MONTH(NOW())');
到
$where = 'MONTH(c.cashDate) = MONTH(NOW())';