I am currently working on a hotel booking system. There are 4 rooms types, 3 have 5 rooms and 1 has 10 rooms. I have everything working apart from the ability to check which are booked or not.
The SQL I used to create the tables is listed below;
CREATE TABLE `Rooms` (
`roomID` tinyint(2) NOT NULL auto_increment,
`roomType` tinyint(1) NOT NULL,
`occupied` tinyint(1) NOT NULL,
PRIMARY KEY (`roomID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=26 ;
CREATE TABLE `Bookings` (
`bookingID` tinyint(4) NOT NULL auto_increment,
`userID` tinyint(4) NOT NULL,
`roomID` tinyint(2) NOT NULL,
`roomType` tinyint(1) NOT NULL,
`bookingDate` date NOT NULL,
`dateFrom` date NOT NULL,
`dateTo` date NOT NULL,
`cost` decimal(4,2) NOT NULL,
`fulfilled` tinyint(1) NOT NULL,
PRIMARY KEY (`bookingID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
CREATE TABLE `RoomTypes` (
`roomType` tinyint(1) NOT NULL auto_increment COMMENT '1 = FB, 2 = SDB, 3 = TB, 4 = SB',
`price` decimal(4,2) NOT NULL COMMENT 'Per night',
PRIMARY KEY (`roomType`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
My current fucntion to check the availability is;
function dateCheck($date1, $date2) {
global $mysqli;
global $roomType;
$dates = $mysqli->query("SELECT * From Bookings WHERE ('$date1' BETWEEN dateFrom - INTERVAL 1 DAY AND dateTo - INTERVAL 1 DAY) AND ('$date2' BETWEEN dateFrom - INTERVAL 1 DAY AND dateTo - INTERVAL 1 DAY)") or die($mysqli->error);
$datesRows = $dates->num_rows;
$check = $mysqli->query("SELECT * From Bookings WHERE occupied = 0 AND roomType = '$roomType'") or die($mysqli->error);
$checkRows = $check->num_rows;
var_dump($datesRows);
while($checkOB = $check->fetch_object()){
echo "Room ID: " . $checkOB->roomID . ".<br />";
}
}
$date1 and $date2 are read in from a form.
Any help or even an indication of the way to go about this would be great.