【发布时间】:2016-10-09 20:38:57
【问题描述】:
控制器
这是控制器页面。
public function index() {
$data = array(
'year' => $this->year_model->list_all(),
'speces' => $this->speces_model->list_all(),
);
foreach ($data['year'] as $value):
$temp = array();
$temp['year_key'] = $value['year-range'];
$temp['year_id'] = $value['id'];
$temp['speces_key'] = array();
foreach ($data['speces'] as $value1):
$temp['speces_key'][$value1['name']] = $this->db->get_where('expendituredata', array('spacesId' => $value1['id'], 'yearId' => $value['id']))->row_array();
endforeach;
$final_result[] = $temp;
endforeach;
$data['result'] = $final_result;
$this->load->view('site/template', $data);
}
查看
这是查看文件。
<table>
<thead>
<tr>
<th>Year Range</th>
<?php foreach ($speces as $value): ?>
<th> <?php echo $value['name']; ?></th>
<?php endforeach; ?>
<th>TOTAL</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $value): ?>
<?php $sum = 0; ?>
<tr>
td><?php echo $value['year_key']; ?></td>
<?php foreach ($value['speces_key'] as $key => $value2): ?>
<td><?php echo $value2['data']; ?></td>
<?php $sum+= $value2['data']; ?>
<?php endforeach; ?>
<td><?php echo $sum; ?></td>
</tr>
<?php endforeach; ?>
<tr>
<td>Total</td>
</tr>
</table>
我的问题:如何在上面的屏幕截图中计算总计。
所以请查看上面的截图和按年份计算所有动物的总数。
【问题讨论】:
-
在 SQL 查询中做
-
显示您的预期结果?
标签: php mysql codeigniter