我正在使用预订系统,用户可以预订他们的汽车,在数据库/表格中添加任何行程之前我想检查日期和时间之间已存在的行程。这是我的模型中的查询。
$this->db->select('trId')
->from('trips')
->where('carId',$data['carId'])//car Id
->where('tripStart <=',$data['tripStart'])//trip start date
->where('tripEnd >= ',$data['tripEnd'])//trip end date
->where('tripStartTime <= ',$data['tripStartTime'])//trip start time
->where('tripStartEnd >=',$data['tripStartEnd'])//trip end time
->get();
我在旅行表中存储了值
tripStart = '2018-03-01'
tripEnd = '2018-03-03'
tripStartTime = '09:00:00'
tripStartEnd = '13:00:00'
select trId from trips
where carId = value AND
(Between tripStart = "value" AND tripEnd = "value") AND
(Between tripsStartTime = "value" AND tripStartEnd = "value");
这就是你想要的
是的,你可以但在此之前你必须连接sql列进行比较 知道qazxsw poi qazxsw poi
您还需要使用SQL
PHP函数将变量组合到datetime中
CONCAT