|
Posted by J. Frank Parnell on 09/07/07 09:20
arrrrrg:
Condo for rent has 3 price tiers (for different times of the year):
value
regular
premium
For every 7 nites they stay, they get 1 free, and that free one should be the
cheapest night (1 value nite, 6 premium nites, they should get the value nite
free)
main script:
$_POST['vnites'] = 2; $_POST['rnites'] = 0; $_POST['pnites']=12;
$totalnites = $_POST['vnites'] + $_POST['rnites'] + $_POST['pnites'];
echo 'totalnites= '. $totalnites.'<BR><BR>';
$postNights = array('vnites' => $_POST['vnites'] , 'rnites' => $_POST['rnites']
, 'pnites' => $_POST['pnites']);
if (($totalnites > 6)AND($totalnites < 14)){$mult = 1;}
if (($totalnites > 13)AND($totalnites < 21)){$mult = 2;}
if (($totalnites > 20)AND($totalnites < 28)){$mult = 3;}
if (($totalnites > 27)AND($totalnites < 35)){$mult = 4;}
if (($totalnites > 34)AND($totalnites < 42)){$mult = 5;}
$temptotalnites = $totalnites;
if ($totalnites > 6){ // call the func:
$discountnites = subtractFreeDays($postNights ,$temptotalnites, $mult);
echo '<PRE>after func $discountnites=';
print_r($discountnites);
echo '</PRE>';
}
func:
<?php
function subtractFreeDays($fpostNights, $ftotalnites, $fmult){
echo 'in func mult: '.$fmult.'<BR>';
echo 'in func $fpostNights[vnites]: '.$fpostNights['vnites'].'<BR>';
echo 'in func $discvnites='.$discNights['vnites']."<BR><BR>";
if ($fmult > 0){
if($fpostNights['vnites'] > 0){//echo'1';
$discNights['vnites'] = $discNights['vnites'] + 1;
echo '$discvnites='.$discNights['vnites']."<BR>";
$fpostNights['vnites'] = $fpostNights['vnites'] - 1;
echo '$fpostNights[vnites]='.$fpostNights['vnites']."<BR><BR>";
}
elseif($fpostNights['rnites'] > 0){
$discNights['rnites'] = $discNights['rnites'] + 1;
$fpostNights['rnites'] = $fpostNights['rnites'] - 1;
}
else{
$discNights['pnites'] = $discNights['pnites'] + 1;
$fpostNights['pnites'] = $fpostNights['pnites'] - 1;
}
//echo 'before minusing fmlut='.$fmult."<BR>";
$fmult = $fmult - 1;
if ($fmult >= 1){
echo 'before recurse $fmult= '.$fmult.'<HR>';
subtractFreeDays($fpostNights, $ftotalnites, $fmult);
}else{
echo '<PRE>returning:';
print_r($discNights);
echo '</PRE>';
return $discNights;
}
}
//shouldnt get here
return array('shouldnt','get','here');
}
?>
-- This works on less than 14 days.
Over 14 days, it breaks:
1. $discNights['vnites'] is being reset to nothing every recursion, what gives?
2. I get to
echo '<PRE>returning:';
print_r($discNights);
echo '</PRE>';
return $discNights;
and it *does* print_r (wrong value, see #1), but it doesnt seem to return, and
that really chaps my hide. It will keep going, eventually returning the
array('shouldnt','get','here').
Thanks for your time,
[Back to original message]
|