嘿伙计们,我有一个 mysql 查询,它从数据库表中读取一些记录。$key->r4、$key->sr13 和 $key->huawei 字段完美显示,但我无法得到三者的总和。这是我的代码:
$total_r4=0;$total_sr13=0;$total_huawei=0;
foreach($view_data->result() as $key){
$total_r4 += $key->r4;
$total_sr13 += $key->sr13;
$total_huawei += $key->huawei;
echo "<tr>";
echo "<td>$key->date";
echo "<td>$key->time";
echo "<td>$key->r4";
echo "<td>$key->sr13";
echo "<td>$key->huawei";
echo "<td>".$key->r4 + $key->sr13 + $key->huawei;
}
问题实际上是在最后一行没有对 3 个变量求和!