我想在CodeIgniter中选择dateStart和dateEnd之间的空闲房间。
我有2张桌子 - 房间和预订。
我当前的型号代码:
$this->db->select('rooms.*');
$this->db->join('reservations', 'rooms.ID = reservations.RoomID', 'left outer');
$this->db->where('rooms.Size >=', $PeopleNumber);
$this->db->where('reservations.DateStart <=', $DateEnd);
$this->db->where('reservations.DateEnd >=', $DateStart);
$this->db->group_by('rooms.Size');
$query = $this->db->get('rooms');
我已经检查了这个问题:MySQL Looking for free rooms in reservation system
但我不知道如何在CodeIgniter中进行多选。
我的SQL小提琴:http://sqlfiddle.com/#!9/c1f95/8
答案 0 :(得分:0)
好的,我解决了这个问题:
$this->db->where('`ID` NOT IN (SELECT `RoomID` FROM `reservations` WHERE `DateStart` < "' .$DateEnd. '" AND `DateEnd` > "' .$DateStart. '")', NULL, FALSE);