php - mysql check next and previous available period in room availability query -
for project of mine add feature show previous , next available period in booking reservation system.
i have query checks if house available:
select id tbl_reservations ( `status` 'confirmed' or `status` 'total-payed' ) , ( '2015-08-12' between checkin , checkout or checkout between '2015-08-12' , '2015-08-13' or '2015-08-12' between checkin , checkout or checkin between '2015-08-12' , '2015-08-13' );
if finds reservation in period, php script return false, shows message
"sorry, no availability in selected period"
i show like:
"the next available period stay of xx nights is: "
and show checkin , checkout date.
same thing previous period.
i not mastering sql 100%, here asking suggestions of kind point me in right direction.
here 2 solutions.
get next available reservation expected stay:
select id tbl_reservations ( `status` != 'confirmed' , `status` != 'total-payed' ) , checkin = (select min(checkin) tbl_reservations checkin > '2015-08-12' , checkout - checkin >= '2015-08-12' - '2015-08-13');
get previous reservation expected stay.
select id tbl_reservations ( `status` != 'confirmed' , `status` != 'total-payed' ) , checkin = (select max(checkin) tbl_reservations checkin < '2015-08-12' , checkout - checkin >= '2015-08-12' - '2015-08-13');
these can combined 1 query, question looked wanted 2 separate queries. these tested , ready go..
Comments
Post a Comment