Jump to content
sunziun

PHP Min Max

Recommended Posts

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!

Share this post


Link to post
Share on other sites

What error messages are you getting? Many errors are possible.

Edited by niche

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

I dont get any error message, I just dont know to do this simple calculation via php!?

Share this post


Link to post
Share on other sites
Guest So Called
$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.

Edited by So Called

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Guest So Called

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...