Page 1 of 1

Need help with a calculation...

Posted: Thu Dec 15, 2005 4:19 am
by michlcamp
I've got a shipping calculation that goes like this:

Code: Select all

Shipping: <?php if ($total > 81.75) {printf ("%01.2f", $total * .11);}else {echo "8.99 ";}?>
but I need to add another calculation, IF the order is from a country other that the U.S. - something like,

if ($country is NOT USA, * .25)

I still need the other two parts to work the same as they have been if the order is from the U.S, but need to multiply $total by 25% if outside of the US, regardless of $total...

so, in non-php terms... IF $country is USA, AND $total > 81.75, printf $total * .11,

but IF $ country is NOT USA, printf $total * .25

also needs to go into a hidden field to pass to the next page...

Code: Select all

<input type="hidden" name="shipping" value="<?php if ($total > 81.75) {printf ("%01.2f", $total * .11);} else {echo "8.99 ";}?>">
Don't know how to write multiple IFs...
Any/all help appreciated...
thanks in advance.
mc

Posted: Thu Dec 15, 2005 1:14 pm
by shiznatix
just do somtin like

Code: Select all

<?php
if ($country == 'USA')
{
    if ($total > 81.75)
        $show =  $total * 0.11;
    else 
        $show = 8.99;
}
else
{
    if ($total > 81.75)
        $show =  $total * 0.11 * 0.25;
    else 
        $show = 8.99 * 0.25;
}
?>

<input type="hidden" name="shipping" value="<?= $show ?>">

Posted: Thu Dec 15, 2005 2:36 pm
by m3mn0n
For the sake of debugging, I'd really recommend splitting up if conditional onto multiple lines