【问题标题】:PHP handling the display of some calculationsPHP 处理一些计算的显示
【发布时间】:2015-01-19 16:29:18
【问题描述】:

我正在尝试计算页面上的某些内容,测试回显工作正常,但不会显示在正确的“if”部分中。出于某种原因,它不断触发最后一个 else - 嗯? - 部分。在里面工作了几个小时后,我感到很困惑。

是的,我是 php 的新手...我敢肯定这是我在这里缺少的一些简单的东西。

<? $balance = number_format(($due - $paid), 2, '.', ''); ?>
<? echo $due; ?> - 
<? echo $paid; ?> = 
<? echo $balance; ?><br>
<? if (($balance = 0) AND ($paid = 0)) { ?>
    <a href="createworkorder.php?id=<?=$id?>&step=4" title="This ticket has no charges."><strong>$<?=number_format(($balance), 2, '.', ''); ?></a></strong>
<? } elseif ($balance > 0) { ?>
    <a href="createworkorder.php?id=<?=$id?>&step=4" title="Click to pay or print."><strong><font color="red">$<?=number_format(($balance), 2, '.', ''); ?></font></strong></a>
<? } elseif (($balance = 0) AND ($paid > 0)) { ?>
    <a href="createworkorder.php?id=<?=$id?>&step=4" title="PAID IN FULL. Ready to close"><strong><font color="lime">$<?=number_format(($balance), 2, '.', ''); ?></font></strong></a>
<? } else { ?>
    <a href="createworkorder.php?id=<?=$id?>&step=4" title="HUH??"><strong>$<?=number_format(($balance), 2, '.', ''); ?></a></strong>
<? } ?>

【问题讨论】:

  • 你是在分配而不是比较。

标签: php if-statement echo


【解决方案1】:

您正在使用赋值运算符 (=),而您应该使用比较运算符 (==)。

<? if (($balance = 0) AND ($paid = 0)) { ?>

应该是

<? if (($balance == 0) AND ($paid == 0)) { ?>

【讨论】:

  • @NeilP 如果您还没有看过它,您可以在这里参观:stackoverflow.com/tour,看看该网站是如何运作的! (顺便说一句:您可以接受如何帮助您最大并解决您的问题的答案!)
猜你喜欢
  • 2013-10-17
  • 2020-07-16
  • 2018-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-30
  • 2018-04-16
相关资源
最近更新 更多