PHP Mysqli从数据库中计算检索到的值

时间:2015-10-05 19:52:31

标签: php mysqli

我有一个包含3个表的数据库。表A包含描述和价格等的商品。有2列价格:第一价格和销售价格。表B包含客户详细信息和表C订单。我用" SELECT商品打印到页面。,客户​​。,订单。*从商品,客户,订单到哪里...." '客户'和'订单'包含一个用于帐单编号的列,因此如果客户订购,则会在' orders'中包含一个新行。对于在列中使用相同帐单编号购买的每件商品。如何显示订单,客户详细信息和账单编号只显示一次,然后只列出相应的订购商品? 为了计算订单总数,我做了这个:

    if(empty($row["PriceSale"])||$row["PriceSale"]=='0.00')
    {
       $Price=$row["Price"];
    }else{
       $Price=$row["PriceSale"];
    }

    $sum = 0;
    $amount = $row["Amount"];
    $NPrice = $Price*$amount; //for total of one item (per row)

    $sum    = ($sum + $NPrice); //if this line is not there, then the $total_sum will have no effect
    $sum    = number_format($sum,2);

现在我做的时候:

    $total_sum += str_replace(",", "", $sum);

然后它会计算价格总和,但它也会显示“通知:未定义变量:$ total_sum ....'当我执行$ totalsum = 0时,它将计算错误。那么,怎么做呢?

0 个答案:

没有答案