我想用这样的codeigniter构建一个查询.
SELECT*FROM
tableWHERE machine = $ var AND date BETWEEN' $ today'和'$ 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();
}
}
Run Code Online (Sandbox Code Playgroud)
我一直在尝试,但我没有得到结果加:用这行可以计算一个月前的日期
$today = date('Y-m-d');
$month=date('Y-m-d',strtotime("-1 month"));
Run Code Online (Sandbox Code Playgroud)
对不起我的英文xP
请尝试以下代码: -
public function getHistory($machine)
{
$today = date('Y-m-d');
$query = $this->db->from('table')
->where('machine', $machine)
->where('date >=', (NOW() - INTERVAL 1 MONTH))
->get();
if ($query->num_rows() > 0)
{
return $query->result();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |