我已經從數據庫中檢索了一些值。在我的視圖文件中,我有以下內容:如何總結數組內的值?
$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'];內存在的所有值。然後顯示它。但我不知道如何總結。我在上面發佈我的視圖文件;請檢查它:)謝謝 –