我似乎无法弄清楚我的代码是什么,我无法获得总价值

时间:2016-03-10 09:13:15

标签: php

我无法得到总值,它显示为0.任何人都可以帮我处理这部分代码。

while($test = mysql_fetch_array($result))
{
  $customer_id= $test['customer_id'];

  $total = ($test['price']*$test['qty']);

  echo "<tr>"; 
  echo "<td>". $test['name']. "</td>";
  echo "<td>". $test['email']. "</td>";
  echo "<td>". $test['p_num']. "</td>";
  echo "<td>". $test['address']. "</td>";
  echo "<td>". $test['message']. "</td>";
  echo "<td>". $test['ord']. "</td>";
  echo "<td>". $test['price']. "</td>";
  echo "<td>". $test['qty']. "</td>";
  echo "<td>". $total. "</td>";
  echo "<td>". $test['ord_date']. "</td>";

1 个答案:

答案 0 :(得分:1)

如果price或qty为0,则检查每个循环的价格和数量值,它将返回0;

您需要对所有迭代值求和

$total += ($test['price']*$test['qty']);