我在数据库中有2个表。 我需要从数据库中获取我所给的时间和日期中没有预订的所有房间。
房间:
id int(11)
name varchar(15)
预订:
id int(11)
room_id int(11)
date date
time_start time
time_finish time
我的功能
public function get_free_rooms() {
$date = $this->input->post('date', true);
$time_start = $this->input->post('time_start', true);
$time_finish = $this->input->post('time_finish', true);
$query = $this->db->join('reservations','rooms.id = reservations.room_id','left')
->where('reservations.id IS NULL', null, false)
->where('reservations.date', $date)
->where('reservations.time_start<', $time_start)
->where('reservations.time_finish>', $time_finish)
->get('rooms');
$query = $query->result();
echo json_encode($query);
}
我的预订表现在为空。当我提供数据时:
$ date = 2019-05-29,$ time_start = 10:00:00,$ time_finish = 13:00:00
查询结果为空数组,应返回所有房间,因为没有预订。