[英]query for available rooms in hotel reservation between two dates
I need to select just the available rooms in hotel reservation system 我只需要在酒店预订系统中选择可用的房间
Here's my query 这是我的查询
echo $str = $_POST['start'];
echo $en = $_POST['end'];
$sql = "SELECT *
FROM chambre
WHERE id NOT IN (SELECT id_chambre
FROM reservation_client
where start < $en
or end >=$str)";
But the query gives me the rooms that are not in table reservation_client
not the rooms available between $str
and $en
date 但是查询给了我不在表
reservation_client
的房间,而不是在$str
和$en
日期之间可用的房间
You can use a LEFT JOIN
instead, and see where the reservations are NULL
(meaning there were no left joins). 您可以改用
LEFT JOIN
,然后查看保留为NULL
(这意味着没有左连接)。
SELECT c.*
FROM chambre AS c
LEFT JOIN reservation_client AS rc
ON c.id = rc.id_chambre AND rc.start < '$en' AND rc.end >= '$str'
WHERE rc.id_chambre IS NULL
Though you should be using a prepared statement and bind your values through placeholders instead. 尽管您应该使用准备好的语句,而是通过占位符绑定值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.