这是我从我的 PHP 脚本中看到的输出:
Cash Completions (Purchase)
Product A: £435.60
Product B: £38.40
Product C: £0.00
Product D: £3,349.87
Product E: £559.38
Product F: £0.00
Product G: £0.00
Product H: £0.00
TOTAL COSTS: £1,036.38
看看最后一行,“总成本”。您会看到它不等于上面所有行的总和。
这是用于计算此值的 PHP 脚本:
Cash Completions (Purchase)
Product A: <?php echo '£'.$extra->a;?>
Product B: <?php echo '£'.$extra->b;?>
Product C: <?php echo '£'.$extra->c;?>
Product D: <?php echo '£'.$extra->d;?>
Product E: <?php echo '£'.$extra->e;?>
Product F: <?php echo '£'.$extra->f;?>
Product G: <?php echo '£'.$extra->g;?>
Product H: <?php echo '£'.$extra->h;?>
TOTAL COSTS: <?php echo '£'.number_format($extra->a + $extra->b + $extra->c + $extra->d + $extra->e + $extra->f + $extra->g + $extra->h, 2);?>
该$extra
变量是一个表示 MySQL 结果集的对象。如您所见,单个产品的输出是正确的,但由于某种原因,总数相差甚远。
有任何想法吗?
谢谢!