【发布时间】:2016-10-22 01:40:48
【问题描述】:
我需要以下帮助。需要将我的类别与金额分组,然后在底部加上总和。并计算每个类别的百分比
echo print_r($results);
Array
(
[0] => stdClass Object
(
[expense_category] => Salary
[expense_amount] => 100
)
[1] => stdClass Object
(
[expense_category] => Electricity
[expense_amount] => 30
)
[2] => stdClass Object
(
[expense_category] => Gas
[expense_amount] => 15
)
[3] => stdClass Object
(
[expense_category] => Gas
[expense_amount] => 10
)
)
我正在尝试获得以下输出:
+--------------------------+--------------+----------+
|Expense Category|cat_count|Expense Amount|Percentage|
+--------------------------+--------------+----------+
|Salary |1 |100 |65% |
|Electricity |1 |30 |19% |
|Gas |2 |25 |16% |
+----------------+---------+--------------+----------+
|TOTAL |4 |155 |100% |
+----------------+---------+--------------+----------+
以下需要帮助:
<table>
<tr>
<th>Expense Category</th>
<th>cat_count</th>
<th>Expense Amount</th>
<th>Percentage</th>
</tr>
<tr>
<td><?php echo $category ?></td>
<td><?php echo $cat_count ?></td>
<td><?php echo $amount ?></td>
<td><?php echo $percent ?></td>
</tr>
<tr>
<th>TOTAL</th>
<th><?php echo $Count_Sum; ?></th>
<th><?php echo $Cat_Sum; ?></th>
<th>100%</th>
</tr>
</table>
【问题讨论】:
-
还有……你有没有尝试自己写一些东西?或者你在找人帮你做作业?
标签: php codeigniter loops sum