Re: BOOKING SYSTEM
| From: | php @ net mines | Date: | Wed, 21 Sep 2005 10:48:18 +0000 |
| Subject: | Re: BOOKING SYSTEM | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-222859@lists.php.net to get a copy of this message | ||
Got the solution finally!!! The code is not optimised yet but here it is:
(The accomodation holds total availability and the accomodation1 the bookings...)
function checkspecificdate($thespecificdatefrom,$thespecificdateto,$productid) {
list($dd1,$mm1,$yyyy1) = split("/", $thespecificdatefrom);
list($dd2,$mm2,$yyyy2) = split("/", $thespecificdateto);
$thespecificdateto = $yyyy2 . "-" . $mm2 . "-" . $dd2;
$thespecificdatefrom = $yyyy1 . "-" . $mm1 . "-" . $dd1;
$i=0;
$z=0;
while ($aday_later < $thespecificdateto) {
$aday_later = date("Y-m-d",mktime(0,0,0,$mm1,$dd1+$i,$yyyy1));
$theas = 0;
$thead = 0;
$theat = 0;
$theaq = 0;
$thequery01 = "SELECT *";
$thequery01 .= " FROM accomodation";
$thequery01 .= " WHERE accomodation_products_id=" . $productid . " AND accomodation_from<='" . $aday_later . "' AND accomodation_to>='" . $aday_later . "'";
$result01 = mysql_query($thequery01);
if ($result01) {
while ($thes = mysql_fetch_array($result01)) {
$theas = stripslashes($thes["accomodation_single"]);
$thead = stripslashes($thes["accomodation_double"]);
$theat = stripslashes($thes["accomodation_triple"]);
$theaq = stripslashes($thes["accomodation_quadriple"]);
}
}
$theas3 = 0;
$thead3 = 0;
$theat3 = 0;
$theaq3 = 0;
$thequery01 = "SELECT SUM(accomodation1_single) AS theas3, SUM(accomodation1_double) AS thead3, SUM(accomodation1_triple) AS theat3, SUM(accomodation1_quadriple) AS theaq3";
$thequery01 .= " FROM accomodation1";
$thequery01 .= " WHERE accomodation1_products_id=" . $productid . " AND accomodation1_from<='" . $aday_later . "' AND accomodation1_to>='" . $aday_later . "'";
$result01 = mysql_query($thequery01);
if ($result01) {
while ($thes = mysql_fetch_array($result01)) {
$theas3 = stripslashes($thes["theas3"]);
$thead3 = stripslashes($thes["thead3"]);
$theat3 = stripslashes($thes["theat3"]);
$theaq3 = stripslashes($thes["theaq3"]);
}
}
if (($theas - $theas3<=0) || ($thead - $thead3<=0) || ($theat - $theat3<=0) || ($theaq - $theaq3<=0)) {
$z++;
}
$i++;
}
return $z;
}
if (checkspecificdate($thedate1,$thedate2,$productid)==0) {
//ALLOW BOOKING
} else {
//DO NOT ALLOW BOOKING
}
----- Original Message ----- From: "adriano ghezzi" <adriano.ghezzi@gmail.com>
To: <php-general@lists.php.net>
Sent: Wednesday, September 21, 2005 2:09 AM
Subject: Re: [PHP] BOOKING SYSTEM
well I did it in the past, at the end after a lot of tests and simulation i decided for warehouse table id_hotel, date, num_total_rooms, num_booked_rooms this is day by day handling it is really flexible you can satisfy each kind of request with very simple queries you also gain more flexibility in period definition you canalso easily handling dsingle day workout and so on 2005/9/20, php @ net mines <php@netmines.gr>:Hi all I have a hotel booking system where for sppecific periods we have specific availability e.g. hotel_id, hotel_name, hotel_fromperiod, hotel_toperiod, hotel_availablesinglerooms 1, Hilton, 20/06/05, 20/08/05, 20 We have a second table for recording the bookings e.g.hotel1_id, hotel1_name, hotel1_fromperiod, hotel1_toperiod, hotel1_availablesinglerooms 1, Hilton, 01/07/05, 20/07/05, 1 2, Hilton, 20/06/05, 25/07/05, 1 3, Hilton, 25/06/05, 27/06/05, 19 4, Hilton, 05/07/05, 05/08/05, 2 Let's say that someone wants to book from the 25/06/05 - 29/06/05 what kind of function-SQL do I have to run to check whether there is availability? (in this example there should be availability between 27 and 29 but not between 25 and 27). Is this way of structuring the easiest and more efficient? Thank you Mario -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php