Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL Expert Required!! Advanced Query Problem


MySQL Expert Required!! Advanced Query Problem

Reply
  #1 (permalink)  
Old 02-28-04, 01:22 PM
bluey_the_punch bluey_the_punch is offline
New Member
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation MySQL Expert Required!! Advanced Query Problem

I am currently developing a hotel booking system for my University final year project and am having some serious problems with my query to calculate room availability.

I felt the best method to calculate room availability was to first calculate which rooms were already booked for any specific queried dates and then to subtract those results from the list of total rooms. That would then return which rooms were available on those dates.

However the query that I am using to calculate which rooms are already booked is very inefficient, in that, for example,

A booking which is for more than one night can overlap the date you are testing for availability. It's even worse when you check the availability of rooms for multiple nights. My query does not cover those scenarios.

If anyone can help me solve this problem or suggest alternative methods I would be most appreciative.

Below is the MySQL code for the relevant parts of my database, and the query that I am currently using.

Thanks!


CREATE TABLE booking
(
booking_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
e_mail VARCHAR(40) NOT NULL REFERENCES guestdetails(e_mail),
arrival_date DATE NOT NULL,
departure_date DATE NOT NULL,

PRIMARY KEY(booking_id)
);

CREATE TABLE roombooked
(
booking_id INTEGER UNSIGNED NOT NULL REFERENCES booking(booking_id),
room_id INTEGER UNSIGNED NOT NULL REFERENCES rooms(room_no),
no_of_nights INTEGER UNSIGNED NOT NULL,

PRIMARY KEY(booking_id,room_id)
);

CREATE TABLE rooms
(
room_no INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
room_name VARCHAR(11),
room_type VARCHAR(9),
single_price DECIMAL(5,2),
double_price DECIMAL(5,2),

PRIMARY KEY(room_no)
);

insert into rooms (room_name,room_type,single_price,double_price)
values ('shakespeare','principal','165','225'),
('keats','principal','165','225'),
('kipling','standard','125','165'),
('tennyson','superior','135','185'),
('shelley','deluxe','155','205'),
('brooke','superior','135','185'),
('wordsworth','deluxe','155','205'),
('milton','deluxe','155','205'),
('masefield','deluxe','155','205'),
('browning','deluxe','155','205');


///ROOM AVAILABILITY QUERY///


CREATE TEMPORARY TABLE roomsoccupied
SELECT roombooked.room_id FROM roombooked, booking
WHERE
roombooked.booking_id = booking.booking_id
AND
booking.arrival_date <= 'QueriedArrivalDate'
AND
booking.departure_date >= 'QueriedDepartureDate';
Reply With Quote
  #2 (permalink)  
Old 02-28-04, 01:37 PM
AvanteGuard AvanteGuard is offline
Newbie Coder
 
Join Date: Feb 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Haven't tested it, but

SELECT * FROM booking WHERE (arrival_date>%searchdate% OR departure_date<%searchdate%)

Hope that helps.

Regards,

Matthew Madigan
Structure and Design Systems
a Division of Imadigan Holdings, LLC.
mmadigan@structureanddesign.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP:search by MySQL query lowdog PHP 0 02-15-04 10:04 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
creating calculated fields in mysql resource after query Abu Mami PHP 0 07-31-03 06:47 AM


All times are GMT -5. The time now is 09:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.