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.
Assuming that you have stored our check-in and check-out dates in the format 'dmY' >ou could execute the following SQL statement:
SELECT COUNT(acomm_id) FROM Accomm WHERE checkin <= yourDateString AND checkout => yourDateString
Hope this helps.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.