-5

为什么它仍然获得取消状态的房间?有人能帮帮我吗?正确的语法应该是什么?

$que=mysql_query("SELECT * from roomreservation where roomtype='$roomtype' and name='$name' and status != 'cancelled' and  

arrival > '$arrival' and arrival < '$departure' and
or
departure >'$arrival' and  departure <'$departure' and
or
'$arrival'  > arrival and '$arrival' < departure and
or
'$departure' > arrival and '$departure' < departure and
or
'$arrival' = arrival and '$departure' = departure and
or
'$arrival' = arrival or '$departure' = departure and


");

$num_rows = mysql_num_rows($que);
if($num_rows >0)
    {   $error="Room Already Reserved <br/>Please Choose another date";
        header("location:rescheduleroom.php?    id=$id&type=$roomtype&roomnumber=$name&error=$error");
            }
4

2 回答 2

1

您的逻辑非常复杂。它可以归结为:

SELECT ...
WHERE roomtype='$roomtype' and name='$name' and status != 'cancelled'
   and ('$departure' >= arrival) and ('$arrival' <= departure)

从本质上讲,您有以下内容。一个可用/不可用的房间,以及关于潜在到达/离开日期如何与该可用性重叠的一系列选项

room:      ........XXXXXXXXX.......   <--- . = available, X = in use
         1    A  D
         2       A    D
         3           A    D
         4              A      D
         5                    A   D

案例 1 和 5 显然是可用的 - A/D 时间点不与房间的不可用重叠。2,3,4 是大的,它们部分/完全与停电期重叠。但是如果你仔细观察,在所有需要考虑的情况下,A是在停电结束之前,在停电D开始之后,所以你的巨大丑陋和/或链条只是

   ('$arrival' <= departure) AND ('$departure' >= arrival)
于 2013-02-28T14:48:08.983 回答
1

尝试类似:

 SELECT * from roomreservation where  
   roomtype='$roomtype' and name='$name' and status != 'cancelled' and  
( arrival > '$arrival' and arrival < '$departure' )  
or  
(departure >'$arrival' and  departure <'$departure')  
or
('$arrival'  > arrival and '$arrival' < departure )
or
('$departure' > arrival and '$departure' < departure )
or
('$arrival' = arrival and '$departure' = departure )
or '$arrival' = arrival or '$departure' = departure

注意:这仍然是一团糟 - 但它更接近

于 2013-02-28T14:19:45.493 回答