chrispos Posted August 8, 2010 Share Posted August 8, 2010 I am using MySQL 5 Good day to you all. I have developed an online booking system for small hotels and but I would like to take this one step further by selection only hotels that have rooms available in a selected area. The code below selects only available rooms from the database. "SELECT * FROM rooms WHERE (hid = '$hid') AND rid NOT IN (SELECT rid FROM bookings WHERE (hid = '$hid') AND ((startdate >= ".$start->getTime()." OR enddate > ".$start->getTime().") AND (startdate < ".$end->getTime().")))"; the tables are rooms for each individual room, rid for individual room id, hid for the hotels individual id, name for the hotels individual name, address for the address and town where the hotel is located. a separate table for bookings holding start dates and departure dates and room id and hotel id. The get time is a bit of php script called date class. So what I am trying to do is amend this script so that only the individual hotels with available rooms appear in the query. I hope this does not sound to complicated as my head is about to explode doing this. Many thanks for looking and have a great day. Quote Link to comment https://forums.phpfreaks.com/topic/210144-hotel-booking-site/ Share on other sites More sharing options...
chrispos Posted August 8, 2010 Author Share Posted August 8, 2010 I am using MySQL 5 Good day to you all. I have developed an online booking system for small hotels and but I would like to take this one step further by selection only hotels that have rooms available in a selected area. The code below selects only available rooms from the database. "SELECT * FROM rooms WHERE (hid = '$hid') AND rid NOT IN (SELECT rid FROM bookings WHERE (hid = '$hid') AND ((startdate >= ".$start->getTime()." OR enddate > ".$start->getTime().") AND (startdate < ".$end->getTime().")))"; the tables are rooms for each individual room, rid for individual room id, hid for the hotels individual id, name for the hotels individual name, address for the address and town where the hotel is located. a separate table for bookings holding start dates and departure dates and room id and hotel id. The get time is a bit of php script called date class. So what I am trying to do is amend this script so that only the individual hotels with available rooms appear in the query. I hope this does not sound to complicated as my head is about to explode doing this. Many thanks for looking and have a great day. I think I may be making this more complicated. I would like to use the above script but add a query at the start. "SELECT * FROM hotels WHERE (town = '$town') rooms WHERE (hid = '$hid') AND rid NOT IN (SELECT rid FROM bookings WHERE (hid = '$hid') AND ((startdate >= ".$start->getTime()." OR enddate > ".$start->getTime().") AND (startdate < ".$end->getTime().")))"; Do you think this will work Quote Link to comment https://forums.phpfreaks.com/topic/210144-hotel-booking-site/#findComment-1096707 Share on other sites More sharing options...
fenway Posted August 10, 2010 Share Posted August 10, 2010 What's not working? Quote Link to comment https://forums.phpfreaks.com/topic/210144-hotel-booking-site/#findComment-1097299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.