用户如何在日期范围内搜索现有房间?
我想创建一个搜索页面,该搜索页面含有一个房间名称,签到和退房日期,以检查是否有房间。
因此,如果用户想搜索预订房间,则必须输入房间名称,入住日期和退房日期,然后单击搜索按钮。
如果房间有现有的预订,并且日期范围与用户输入重叠,则不会显示出来,其他情况。现在,我的SQL输出仅基于房间名称,我不知道为什么它不检查日期重叠。
function search($room, $start, $end) {
$this->db->select(' rId as id,
rName as name,
rCapacity as capacity,
bCheckin as checkin,
bCheckout as checkout,
bBookingTime as bookingtime
');
$this->db->from('room');
$this->db->join('booking', 'rId = brId', 'left');
$this->db->like('rName', $room);
$this->db->where('bCheckout' > $start AND 'bCheckin' < $end);
$this->db->where('brId', NULL);
return $this->db->get()->result_array();
}
这是RAW SQL:
$query = " SELECT rId as id,
rName as name,
rCapacity as capacity,
bCheckin as checkin,
bCheckout as checkout,
bBookingTime as bookingtime
FROM room r
LEFT
JOIN booking b
ON b.brId= r.rId
AND NOT ( $end >= b.bCheckout OR $start<= b.bCheckin )
WHERE r.rName = $room
WHERE b.rbId IS NULL";
return $this->db->query($query)->result_array();
对不起,我无法在此处显示图像,所以我附上上面的链接。
I want to create a search page that takes a room name, check-in, and check-out date to check if a room is available.
So if users want to search rooms for booking they must input room name, check-in date, and check-out date then click the search button.
If a room has an existing booking and the date range overlaps with the user input then it will not show, and otherwise. Now my SQL output is based on the room name only, I have no idea why it does not check for date overlaps.
function search($room, $start, $end) {
$this->db->select(' rId as id,
rName as name,
rCapacity as capacity,
bCheckin as checkin,
bCheckout as checkout,
bBookingTime as bookingtime
');
$this->db->from('room');
$this->db->join('booking', 'rId = brId', 'left');
$this->db->like('rName', $room);
$this->db->where('bCheckout' > $start AND 'bCheckin' < $end);
$this->db->where('brId', NULL);
return $this->db->get()->result_array();
}
This the raw SQL:
$query = " SELECT rId as id,
rName as name,
rCapacity as capacity,
bCheckin as checkin,
bCheckout as checkout,
bBookingTime as bookingtime
FROM room r
LEFT
JOIN booking b
ON b.brId= r.rId
AND NOT ( $end >= b.bCheckout OR $start<= b.bCheckin )
WHERE r.rName = $room
WHERE b.rbId IS NULL";
return $this->db->query($query)->result_array();
Sorry I can't show image here so I attach in above link.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许会有所帮助
Maybe it will helpful