mysql - Booking conflicts using sql -


need advice. trying build booking system integrated our other systems , done apart reliably detecting conflicts of other bookings

my booking database structure quite simple follows

fk_resourceid, startdate, enddate, z_timestart, z_timeend 

i have query fetches data , retrieves resources booked within date range. works great. need add filter checks time well.

select     fk_resourceid,     z_timestart,     z_timeend,    startdate,    enddate  resources   fk_resourceid = 'drama room'   ,  (     (startdate <= ? , enddate >= ?) or     (startdate <= ? , enddate >= ?) or     (startdate >= ? , enddate <= ?) )  order fk_resourceid asc 

i couldn't figure out how include time check did loop through each record query , check against criteria

if(     (z_timestart >= new_booking_start_time  , z_timestart <= new_booking_end_time)  or     (new_booking_start_time  >= z_timestart , new_booking_start_time <= z_timeend);   true ) 

i thought working, unfortunately i've come across scenario fails. data have below.

returned data sql query: 'drama room','08:55','23:55','07/22/2016','07/28/2016' data input in form check: 'drama room','08:05','08:35','07/24/2016','07/24/2016' 

is there simple way implement time search in original sql query, before start hacking conditional statement in loop check dates time? im using combination of filemaker sql , scripts commands try , resolve this. ? query parameter in fm sql.

here correct logic conflicts

select r.* resources r r.fk_resourceid = 'drama room' ,       r.startdate <= $enddate ,       r.enddate >= $startdate order r.fk_resourceid asc; 

Comments