0
我的代码如下我怎样才能总结动态数组
<?php
foreach($query2->result() as $row2)
{
$sub_head_id = $row2->sub_head_id;
?>
<tr>
<?php
$query3 = $this->db->select('farm_id')->get('spf_farm_info'); $she_am_total = 0;
foreach($query3->result() as $row3)
{
$farm_id_inner = $row3->farm_id;
?>
<td>
<?php
$s_h_e_amount = $this->report_model->get_amount($farm_id_inner,$head_id,$sub_head_id);
?>
</td>
<?php
}
?>
<td>
<?php
$total += $s_h_e_amount;
?>
</td>
</tr>
<?php
}
}
?>
基本上我想知道我怎么能解决这个问题,
<tr>
<?php
$query3 = $this->db->select('farm_id')->get('spf_farm_info'); $she_am_total = 0;
foreach($query3->result() as $row3)
{
?>
<td>
<?php
echo "Total :";
echo $total;
?>
</td>
<?php
}
?>
<td>
Grand Total:
</td>
</tr>
这里,表列将动态增加,并会得到不同的从get_amount函数获取每个td的值(可能是2/3/4/..)。
现在我想根据列来总结每个tr的值。 这里它将被动态地总和,这将被显示。
请帮助我,我该如何解决正确
不知道代码点火器,但我会在mysql-query中使用SUM。 – michi 2013-02-24 09:16:33
非常感谢michi。有时候忘记那么容易的事情 – 2013-02-25 11:09:19