用户如何在日期范围内搜索现有房间?

发布于 2025-01-20 15:17:40 字数 1741 浏览 1 评论 0原文

我想创建一个搜索页面,该搜索页面含有一个房间名称,签到和退房日期,以检查是否有房间。

因此,如果用户想搜索预订房间,则必须输入房间名称,入住日期和退房日期,然后单击搜索按钮。

如果房间有现有的预订,并且日期范围与用户输入重叠,则不会显示出来,其他情况。现在,我的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();

room Table

booking Table

Sorry I can't show image here so I attach in above link.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅唱々樱花落 2025-01-27 15:17:40
$query = " SELECT r.Id as id,
                           r.Name as name,
                           r.Capacity as capacity,
                           b.Checkin as checkin,
                           b.Checkout as checkout,
                           b.BookingTime as bookingtime
      FROM room r
      LEFT
      JOIN booking b
         ON b.brId= r.rId
      WHERE
          NOT($end >= b.bCheckout OR $start<= b.bCheckout)
      AND r.rName LIKE $room
      AND b.orderRuangan IS NULL";

也许会有所帮助

$query = " SELECT r.Id as id,
                           r.Name as name,
                           r.Capacity as capacity,
                           b.Checkin as checkin,
                           b.Checkout as checkout,
                           b.BookingTime as bookingtime
      FROM room r
      LEFT
      JOIN booking b
         ON b.brId= r.rId
      WHERE
          NOT($end >= b.bCheckout OR $start<= b.bCheckout)
      AND r.rName LIKE $room
      AND b.orderRuangan IS NULL";

Maybe it will helpful

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文