Reputation: 5724
I'm having a small issue regarding on how to check if a room is booked or not.
So basically I a have a table as shown below
Accomm
What I have so far, is that if the user inputs a checkin and checkout date which are both converted to timestamps. That part is done.
So what i have failed to figure out is the following:
accomm
table for using the checkin and checkout paramters that the user entered. Please assist or guide me on this one. Thanks.
$booked_rooms = 0;
while($accommodation_package = mysql_fetch_array($query)) {
// $this->checkin, $this->checkout are values fed by the user
// $accommodation_package['checkin/out'] are the values in the database
if($this->checkin >= $accommodation_package['checkin'] && $this->checkout <= $accommodation_package['checkout']) {
$booked_rooms +=1;
}
}
echo $booked_rooms;
Well I thought the above would work but when checkin and checkout dates from the client are on different months it does not work.
Upvotes: 0
Views: 781
Reputation: 158
Assuming that you have stored our check-in and check-out dates in the format 'd-m-Y' >ou could execute the following SQL statement:
SELECT COUNT(acomm_id) FROM Accomm WHERE checkin <= yourDateString AND checkout => yourDateString
Hope this helps.
Upvotes: 1
Reputation: 3986
Try with this:
<?php
$currentTime = date('Y-m-d H:i:s');
$sql = "SELECT COUNT(accomm_id)
FROM accom
WHERE checkin <= $currentTime
AND checkout >= $currentTime";
$query = mysqli_query($sql);
// code to get the details.
Upvotes: 0