Jump to content

Problem in my if,elseif and else statement

- - - - -

  • Please log in to reply
2 replies to this topic

#1
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 479 posts
Hi

I encountered a problem in my if,elseif and else statement.

I have this code:

$HDMF = $_POST['HDMF'];


if($TotEarn <= 1500){

    $HMDF = round(($TotEarn * 0.01), 2);

}

elseif ($TotEarn >= 1501) {

    $HDMF = round(($TotEarn * 0.02), 2);

}

else {

    $HDMF = (0);

}

$smarty->assign('HDMF', $HDMF);


I have $TotEarn = 893.5 so that my $HDMF will be 0 right?

But it become blank or empty.

What's wrong in my condition.

Thank you

Edited by Roger, 06 December 2011 - 09:20 PM.
updated title


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
I am confused on why you retrieve $HDMF from POST, only to replace it in all conditions with either another number or zero.

What becomes blank, where? Does Smarty show "blank" instead of whatever $HDMF is?

A little note: You may wish to use > 1500 rather than >= 1501 on your second statement.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 479 posts
I used this code and it works now.



if ($TotEarn <= 1500) {

    $HDMF = round(($TotEarn * 0.01), 2);

} else {

    $HDMF = round(($TotEarn * 0.02), 2);

}  



Thank you so much




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users