dougui1977 2016-03-03 16:40
浏览 75

如何提供合适的查询来检查房间的可用性

I am trying to create a hotel room booking app .... I have created two tables

  • the room table which consists of roomno(PK), room type and room price

  • the availability table which consists of roomno(FK), room type, check-in-date and check-out-date

the PHP code I have created so far allows me to check the availability for a particular type of room for the given dates ...

$type = $_POST['pincode'];
$cin = $_POST['cin'];
$cout = $_POST['cout'];

$sql="select * from avalability where type = '$type' and cout>='$cin' and cin<='$cout'";
$res=mysqli_query($con,$sql);
$check=mysqli_fetch_array($res);
if(isset($check))
{
echo "rooms not available";
}
else
{
echo "rooms available";
$insert="insert into login.avalability(type,cin,cout) values('$type','$cin','$cout')";
mysqli_query($con,$insert);
}
mysqli_close($con);
?>

Now my question: suppose I have 5 single rooms in my room table and one single room has been booked for say 23rd march to 27th march, this makes the other four rooms free ...

But the code I have given doesn't work for this problem ... Can anybody please give me the right query to check room availability properly ?

  • 写回答

1条回答 默认 最新

  • dongyan6235 2016-03-03 17:33
    关注

    I think your availability table isn't really availability, it's reservations. The lifecycle of the data in that table is unclear, but it seems like your query isn't picking up where there is no cin or cout.

    $sql="select * from avalability where type = '$type' and cout>='$cin' and cin<='$cout'"
    

    Should be something like

    $sql="SELECT * FROM avalability WHERE type = '$type' AND ((cout>='$cin' AND cin<='$cout'") OR (cout='' AND cin=''))
    
    评论

报告相同问题?

悬赏问题

  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab