如果我的变量$ amount等于零,我试图回复€00.00
我做错了你可以帮忙吗??
代码
while ($row9 = mysql_fetch_array($result9))
{
$amount = $row9['amount'];
}
//$amount = $amount / 60;
//$amount = round($amount, 2);
if $amount == 0 echo "<b>Balance: €00.00</b>";
else
echo "<b>Balance: $$amount</b>";
答案 0 :(得分:3)
你需要将if / else放在循环中,并且你有一些无效的语法(缺少parens和double $)。所以:
while ($row9 = mysql_fetch_array($result9))
{
$amount = $row9['amount'];
if ($amount == 0)
{
echo "<b>Balance: €00.00</b>";
}
else
{
echo "<b>Balance: $amount</b>";
}
}
答案 1 :(得分:1)
您要向$
添加额外$amount
,请尝试以下操作:
if ($amount == 0) {
echo "<b>Balance: €00.00</b>";
} else {
echo "<b>Balance: $amount</b>";
}
事实上,你可以使你的代码更具可读性/标准:
if ($amount == 0)
{
echo "<b>Balance: €00.00</b>";
}
else
{
echo "<b>Balance: $amount</b>";
}
答案 2 :(得分:0)
我在while循环中移动了if语句,清理了代码并删除了最后一行的额外$符号。
while ($row9 = mysql_fetch_array($result9)) {
if ($row9['amount']) == 0 {
echo "<b>Balance: €00.00</b>";
} else {
echo "<b>Balance: $row9['amount']</b>";
}
}