FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


total counting





redskin
Hallo,

Ik try to count bij selecting 2 different menu's.
The one has a choise like : "Pick up" en "Delivery" (plus 10% extra).
The other has : "Cash" en "Creditcard" (plus 5% extra).
See de code before de filup form tabel.
Code:
if ($type_service == "Delivery"){
$total = round($total_product * 1.10);
} else {
$total = $total_product;
}
if ($payment_methode == "Creditcard"){
$total = round($total_product * 1.05);
} else {
$total = $total_product;
}

If Delivery selected the total wil plus 10%.
If Creditcard selected the total wil plus 5%.
If both Delivery and Creditcard are selected total = (total_product * 0.10) + (total_product * 0.05).
see the code.

Code:
<tabel>
<tr>
<td>Type of service</td><td>:</td>
<td><?php
            if ($type_service == "Delivery"){
                echo $type_service." (10%)";
            } else {
                 echo $type_service." ";
            }
            ?> </td>
</tr>
<tr>
<td>Payment methode</td><td>:</td>
<td>
<?php
            if ($payment_methode == "Creditcard"){
                echo $payment_methode." (5%)";
            } else {
                 echo $payment_methode." ";
            }
            ?>
</td>
</tr>
<tr>
<td>To pay</td><td>:</td>
<td>
<?php   
            $total = $total_product;
            $total .= ($type_service == "Delivery") ? $total_product * 0.10 : 0;
            $total .= ($payment_methode == "Creditcard") ? $total_product * 0.05 : 0;
            echo "<b>  " . round($total) . "</b>";
                        ?>
</td>
</tr>
</table>


Result:
If "Delivery" selected de total plus 10%.
If "Creditcard" selected de total plus 5%.
The problem is if i select both of them de total wil count plus 5%, it must be total = (total_product * 0.10) + (total_product * 0.05).
Is any one know where the mistake is or is there any other way to make right?
Thanks.


edit by rvec: please use code tags in future posts
sonam
First, next time please put code bracket around code. It is for better reading. Maybe is mistake here:
Code:
$total = $totaal_product;


You have two "a" in the $totaal_product.

Sonam
redskin
Hi Sonam,

thanks. i have changed it.
It still doesn't work.
MrBlueSky
Try changing

Code:

$total = $total_product;
$total .= ($type_service == "Delivery") ? $total_product * 0.10 : 0;
$total .= ($payment_methode == "Creditcard") ? $total_product * 0.05 : 0;


to

Code:

$total = $total_product;
$total += ($type_service == "Delivery") ? $total_product * 0.10 : 0;
$total += ($payment_methode == "Creditcard") ? $total_product * 0.05 : 0;
redskin
Mr BlueSky

I tried your advies but it wil count twice

Code:

$total = $total_product;
$total += ($type_service == "Delivery") ? $total_product * 0.10 : 0;
$total += ($payment_methode == "Creditcard") ? $total_product * 0.05 : 0;


any beter idea?
thanks
redskin
Hi...

It took me much time to fix this problem.
Finally i did it.

Many thanks to help me out.
Related topics
Favourite game? (OFFICIAL THREAD)
Can games grow beyond the hard-core set?
Whats your favorites movie series?
useless posts
Photoshop CS2 Total Training Video Workshop
Most popular sites hosted on Frihost...
Phoenix free PHP scripts
Google Total - Much better than the real Google
The history of Violence
Make your own MMORPG !
writing COM components in Perl
showing Gmail storage counting up in your site
Brain Or MIND?
Stereo Total
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.