如何在CodeIgniter中选择免费预订房间 - 两张桌子


How to select free rooms for reservations in CodeIgniter - two tables?

我想在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 在预订系统中寻找免费房间

但我不知道如何在代码点火器中进行多选。

我的SQL小提琴:http://sqlfiddle.com/#!9/c1f95/8

好的,

我解决了这个问题:

$this->db->where('`ID` NOT IN (SELECT `RoomID` FROM `reservations` WHERE `DateStart` < "' .$DateEnd. '" AND `DateEnd` > "' .$DateStart. '")', NULL, FALSE);