我有一个mysql查询来获取两个日期之间的数据:
select * from `bookings` where `durationFrom`='$new_from_date' and `durationTo` between '$new_from_date' and '$new_to_date' 如何用以下方式编写上述查询?
$this->db->select()
->from('bookings')
->where('durationTo',between $new_from_date and $new_to_date)
->where('durationFrom',$new_from_date); 我在用代码点火器..。
这是我的桌子:

我需要在给定的durationFrom和durationTo (用户输入的durationFrom和durationTo )之间选择数据。
如果用户选择了工期,从=2016-02-25,持续时间=2016-08-27,我需要得到所有的5行
如果用户选择了工期,从=2016-02-25和工期到=2016-05-27,我需要得到前3行
发布于 2016-03-17 06:33:29
尝尝这个
$this->db->select('*')
->from('bookings')
->where('durationFrom', $new_from_date)
->where("durationTo BETWEEN '".$new_from_date."' AND '".$new_to_date."'")另一种选择
$this->db->select('*')
->from('bookings')
->where('durationFrom', $new_from_date)
->where('durationTo >= ', $new_from_date)
->where('durationTo <= ', $new_to_date)可以用感兴趣的列名替换select中的*。
发布于 2016-03-17 06:27:50
你可以这样做
$where = "durationTo between "'.$new_from_date.'" AND "'.$new_to_date.'";
$this->db->select('*')->from('bookings')->where('durationFrom',$new_from_date)->where($where); https://stackoverflow.com/questions/36052507
复制相似问题