【问题标题】:How to select free rooms for reservations in CodeIgniter - two tables?如何在 CodeIgniter 中选择免费房间进行预订 - 两张桌子?
【发布时间】:2016-05-18 20:36:46
【问题描述】:

我想在 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

【问题讨论】:

    标签: php mysql codeigniter date


    【解决方案1】:

    好的,我解决了这个问题:

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

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 2015-06-04
      • 2021-10-02
      • 2020-01-31
      • 1970-01-01
      • 1970-01-01
      • 2019-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多