Ive just started using php and mysql a week ago so this should be easy for you guys. I have a series of rates for hotels from now till 2004 all in one table. another table with hotel names and cities. and a third with the room types.
this is wat ive got for the calculation but it wont work. can anyone spot my mistake or suggest alternatives. any help would be much apreciated!
// validate days here
if(!$err) {
$ret = add_days($out, $days);
//echo("Out: ". $out .". Return: ". $ret .".
");
db_connect();
// get rates which might apply
$sql = "SELECT * FROM rates, hotels WHERE rates.hID = (". $hot .") AND rates.valid_from <= \"". $ret ."\" AND rates.valid_to >= \"". $out ."\" ORDER BY hotels.city, valid_from";
if(!$q = db_query($sql)) {
echo("No applicable results found.
");
$err = true;
}
// walk through each rate, adding prices for rates in the correct timeframe and city
$sgl = 0;
$dbl = 0;
$tpl = 0;
// NEEDS UPDATING FOR WEEKDAY/WEEKEND RATES
while($obj = mysql_fetch_object($q)) {
if($obj->city == "Dubai")
$dub_name = $obj->name;
$a = calc_days($obj->valid_from, $obj->valid_to);
$b = so(calc_days($obj->valid_from, $out) - 1);
$c = so(calc_days($out, $obj->valid_to));
$seg = so($a - $b - $c);
//echo($a ." - ". $b ." - ". $c ." = ". $seg ."
");
$d = $out;
$tally = 0;
for($cnt = 1; $cnt <= $seg; $cnt++) {
if(strpos($obj->valid_on, get_day($d)) === false) {
//nothing
} else {
$sgl += $obj->sgl;
$dbl += $obj->dbl;
$tpl += $obj->tpl;
$tally++;
}
$d = add_days($d, 1);
}
//echo($obj->name .", Dubai [h". $obj->hID ."r". $obj->rID ."]: ". $tally ." nights @ ". $obj->sgl ." / ". $obj->dbl ." / ". $obj->tpl .".
");
}
}
//echo("Dubai subtotals: ". $sgl ." / ". $dbl ." / ". $tpl ."
");
db_free_result($qid);
db_close();