【发布时间】:2018-11-23 13:25:03
【问题描述】:
我想用这样的 codeigniter 构建一个查询。
SELECT * FROM
tableWHERE machine=$var AND date BETWEEN '$today' AND '$oneMonthAgo'
这里是我的模态
public function getHistory($machine)
{
$today = date('Y-m-d');
$month=date('Y-m-d',strtotime("-1 month"));
$query = $this->db->from('table')->where('machine', $machine)->where("date BETWEEN '$today' AND '$month'")->get();
if ($query->num_rows() > 0) {
return $query->row();
}
}
我一直在尝试,但我没有得到结果 加:用这条线可以计算一个月前的日期
$today = date('Y-m-d');
$month=date('Y-m-d',strtotime("-1 month"));
对不起我的英语xP
【问题讨论】:
-
为什么不使用
date < '$today' AND date > '$month'?
标签: php codeigniter