这是控制器Page。
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);
}
型号
public function list_all() {
return $this->db->get('year')->result_array();
}
查看
这是查看文件。
<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>
<?php foreach ($speces as $value6): ?>
<?php
$this->db->select_sum('data');
$query = $this->db->get_where('expendituredata', array('spacesId' => $value6['id']))->row_array();
$totals = $query['data'];
?>
<td><?php echo $totals; ?></td>
<?php endforeach; ?>
</tr>
</table>
我的问题:如何计算柱的总和(列名是总).COLUMN名总高于screenshot.so如何计算列的总和显示(列名是总)和总和显示在上面的屏幕截图中的红色箭头
金额无法计算 – kishankakadiya
你看我的屏幕截图,和我的截图显示红色箭头,合计栏的这个红色箭头显示总和(列姓名总数) – kishankakadiya
@kishankakadiya更新了我的答案,请检查,如果它有效? –