我已经从数据库中检索了一些值。在我的视图文件中,我有以下内容:如何总结数组内的值?
$row['fee_amount'];
现在,我想总结$ row ['fee_amount']内的所有值;然后显示它。
我知道我可以在查询数据库时总结一下,但我有兴趣学习如何使用PHP进行添加。
请您好好教我如何做到这一点?
编辑
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>S.N</th>
<th>Fee Type</th>
<th>Fee Amount</th>
</tr>
</thead>
<tbody>
<?php $i = 0; foreach ($records as $row){ $i++; ?>
<tr>
<td><?php echo $i; ?>.</td>
<td><?php echo $row['fee_type'];?></td>
<td><?php echo $row['fee_amount'];?></td>
</tr>
<?php } ?>
</tbody>
<tr>
<td></td>
<td>Total</td>
<td>
I WANT TO DISPLAY THE SUMMATION RESULT HERE ADDING UP VALUES INSIDE THIS>>> <? $row['fee_amount']; ?>
</td>
</tr>
</table>
<?php } ?>
你有什么具体问题?如何总结?如何从数组中获取所有'fee_amount'元素?我想如果你添加更多的代码,你已经做得更清楚了。 – hakre
谢谢Hakre给你回复。让我来描述这个问题。我已经从我的数据库表中提取数据,并且知道何时从数据库中获取信息,这些信息就像数组一样。现在在我的视图文件中(我正在使用Codeigniter),我想总结$ row ['fee_amount'];内存在的所有值。然后显示它。但我不知道如何总结。我在上面发布我的视图文件;请检查它:)谢谢 –