duanjizi9443 2019-02-25 06:28
浏览 56

运行php的MySQL查询问题

I have MySQL table "room_booking" and this table contain two columns 'start_time' and 'end_time'. I want to check the time of the conference room booking. Suppose that if room is booked from 2:10 PM to 3:15 PM. Then another entry should not insert at between this time. My query is

$queryCheck = "SELECT start_time,end_time FROM room_booking AND (SELECT * FROM (room_booking) WHERE (start_time NOT BETWEEN '".$new_start_time."' AND '".$end_start_time."') AND (end_time NOT BETWEEN '".$new_start_time."' AND '".$end_start_time."'))";
  • 写回答

2条回答 默认 最新

  • douyi6818 2019-02-25 06:32
    关注

    This sounds to me to just be the overlapping range problem, and in this case you want to return records which do not overlap with the input start and end times. Try this query:

    SELECT *
    FROM room_booking
    WHERE existing_end < ? OR existing_start > ?;
    

    To the two ? placeholders above, you would bind, in order, $new_start_time and $end_start_time. So, you would end up with the following query:

    SELECT *
    FROM room_booking
    WHERE existing_end > $new_start_time OR existing_start > $end_start_time;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码