开发者

PHP echo text if variable is blank

I am trying to echo €00.00 if my variable $amount equals zero

I have done something wrong can you help??

Cod开发者_StackOverflowe

while ($row9 = mysql_fetch_array($result9))
{
$amount = $row9['amount'];
}
//$amount = $amount / 60;
//$amount = round($amount, 2);
if $amount == 0 echo "<b>Balance: &#8364;00.00</b>";
else
echo "<b>Balance: $$amount</b>";


You need to put the if/else in the loop, and you have some invalid syntax (missing parens and double $). So:

while ($row9 = mysql_fetch_array($result9))
{
  $amount = $row9['amount'];
  if ($amount == 0)
  { 
    echo "<b>Balance: &#8364;00.00</b>";
  }
  else
  {
    echo "<b>Balance: $amount</b>";
  }
}


You are adding extra $ to the $amount, try this:

if ($amount == 0) {
   echo "<b>Balance: &#8364;00.00</b>";
} else {
  echo "<b>Balance: $amount</b>";
}

In fact you can make your code a bit more readable/standard like this:

if ($amount == 0)
{
  echo "<b>Balance: &#8364;00.00</b>";
}
else
{
  echo "<b>Balance: $amount</b>";
}


I've moved the if statement inside the while loop, cleaned up the code and removed the extra $ sign that was on the last line.

while ($row9 = mysql_fetch_array($result9)) {
    if ($row9['amount']) == 0 {
        echo "<b>Balance: &#8364;00.00</b>";
    } else {
        echo "<b>Balance: $row9['amount']</b>";
    }    
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜