sunziun Posted June 22, 2012 Share Posted June 22, 2012 Hello Everyone, right now I am trying to do an small app that can calculate fees based on the price a user has given. Example: $0.01 - $0.99 = $0.09$1 - $5.99 = $0.13$99 or more = $1.34 So far I have this code but I cannot get it to work properly: if($start < 1.00){ echo "<p>" . $ins_fees[0] . $sym . $ins_fees[1] . "</p>"; // FURTHER CALCULATION } if($start == 1.00){ echo "<p>" . $ins_fees[0] . $sym . $ins_fees[2] . "</p>"; // FURTHER CALCULATION } else{ if($start > 1){ echo "<p>" . $ins_fees[0] . $sym . $ins_fees[2] . "</p>"; // FURTHER CALCULATION } } thanks for everyone! Link to comment Share on other sites More sharing options...
niche Posted June 22, 2012 Share Posted June 22, 2012 What error messages are you getting? Many errors are possible. Link to comment Share on other sites More sharing options...
Ingolme Posted June 22, 2012 Share Posted June 22, 2012 You have a condition for each price range From 0 to 0.99: (price < 1) fee = 0.09From 1.00 to 5.99: (price >= 1 && price < 6) fee = 0.1399 or above: (price >= 99) fee = 1.34 Link to comment Share on other sites More sharing options...
sunziun Posted June 22, 2012 Author Share Posted June 22, 2012 I dont get any error message, I just dont know to do this simple calculation via php!? Link to comment Share on other sites More sharing options...
Guest So Called Posted June 22, 2012 Share Posted June 22, 2012 $0.01 - $0.99 = $0.09$1 - $5.99 = $0.13$99 or more = $1.34 if ($amount >= 0.01 && $amount <= 0.99) $fee = 0.09;elseif ($amount <= 5.99) $fee = 0.13;elseif ($amount >= 99) $fee = $1.34; Note that you have some gaps that you will want to fill in. Note also that it is not necessary to test in the second line for > .99 because the first line will have caught that and the second line will not execute. (Beware the $0.00 problem.) If I were writing the code I would structure it a bit differently: if ($amount < 0.01) $fee = 0;elseif ($amount < 1.00) $fee = 0.09;elseif ($amount < 6.00) $fee = 0.13;elseif ($amount < 99.00) $fee = ....;else $fee = $1.34; I'm sure you get the idea. Link to comment Share on other sites More sharing options...
sunziun Posted June 23, 2012 Author Share Posted June 23, 2012 Hello, unfortunately none is working. I have a form which the user enters his amount. Based on that the result.php page should calculate and display the fees applicable. I was playing with range() but I cant find out how to implement the $amount variable. if(range($amount, 0.99, $step) ) echo $fee=0.00;elseif(range($amount,4.99,$step)) echo $fee=0.09; it displays only a 0 (zero) even when i put in amount of 4.50 Link to comment Share on other sites More sharing options...
Guest So Called Posted June 23, 2012 Share Posted June 23, 2012 In my example I used $amount. Evidently you used $start. It's the amount of the transaction, no matter what you call it. It's the value you are looking up to get the fee. Link to comment Share on other sites More sharing options...
sunziun Posted June 25, 2012 Author Share Posted June 25, 2012 I got it now and this works like a charm if($start > 0.00 && $start < 1.00) $fee=0.09; elseif($start > 0.99 && $start < 5.00) $fee=0.13; else echo $fee=1.34; @ So Called the zero problem will be controlled by a minimum form validation of 0.01. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.