I have a reservation system that books trips. Well I need to be able to calculate the total price if any combination of variables are present.
There are 4 main variables:
*Adult Oneway – *Child Oneway –
This is what I have to assign each of those a value:
[code=php]$pricea1 = 39.00; //adult oneway
$pricear = 70.00; //adult roundtrip
$pricec1 = 30.00; //child oneway
$pricecr = 52.00; //child roundtrip
$total1 = number_format($pricea1 * $adult); //total price if adult oneway
$total2 = number_format($pricear * $adult); //total price if adult roundtrip
$total3 = number_format($pricec1 * $child); //total price if child oneway
$total4 = number_format($pricecr * $child); //total price if child roundtrip
$total5 = number_format($total1 + $total2); //total price if adult oneway + adult roundtrip
$total6 = number_format($total1 + $total3); //total price if adult oneway + child oneway
$total7 = number_format($total1 + $total4); //total price if adult oneway + child roundtrip
$total8 = number_format($total2 + $total3); //total price if adult roundtrip + child oneway
$total9 = number_format($total2 + $total4); //total price if adult roundtrip + child roundtrip
Now I need to be able to calculate these and display them in a single input text field.
It needs to be something like this:
[code=php]if ($adult && $trip == “Oneway”) {?><input type=”text” name=”chargetotal” value='<?php echo (“$total1”);?>.00′><?
}
else if ($adult && $trip == “Roundtrip”) {?><input type=”text” name=”chargetotal” value='<?php echo (“$total2”);?>.00′><?
}
else if ($adult && $trip && $child && $trip == “Oneway”) {?><input type=”text” name=”chargetotal” value='<?php echo (“$total5”);?>.00′><?
}
else if ($adult && $trip + $child && $trip == “Roundtrip”) {?><input type=”text” name=”chargetotal” value='<?php echo (“$total6”);?>.00′><?
}
But as you can see, that’s very complicated and there must be an easier way to calculate these totals and have them display in a single text field. The way I am trying above would call for way to many “if’s and else if’s”.
Any ideas?
Thanks