We are building an Reservation booking system. There are three modules
- Customers
- Rooms
- Bookings
A customer can book one or many rooms and for varying dates. While booking a room(s) i want to search for which rooms are available to be booked between date A and date B.
Tables ( likely solution)
customers(id, name, …..)
rooms(id, roomNo, roomType, ….)
bookings(id, room_id, fromDate, toDate)
Presently i have the tables like this
CREATE TABLE IF NOT EXISTS `bookings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`checkin` datetime NOT NULL,
`checkout` datetime NOT NULL,
`advance` int(11) NOT NULL,
`amount` int(11) NOT NULL,
`booking_details_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `bookings_rooms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`booking_id` int(11) NOT NULL,
`room_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `customers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`age` int(11) NOT NULL,
`address` varchar(255) NOT NULL,
`nationality_id` int(11) NOT NULL,
`mobile` int(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `rooms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`number` int(4) NOT NULL,
`category_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
Need help to design the database and which is a better approach.
These schema structures already allow you to find the free rooms between two dates.
The following query will check if rooms booked before start-time will be free before start-time or, for those ones booked after, it checks if they’re checkin is following end-date too.