我想显示来自数据库的for循环内特定字段的总和,这是我在 View 中的代码
<?php foreach($exptype as $exptypes) : ?>
<tr>
<td><?php echo $exptypes->expensestype; ?></td>
<?php
$this->db->select_sum('amount');
$this->db->from('westline_expenses');
$this->db->where('expensestype',$exptypes->expensestype);
$this->db->where('headofexpense','TAX');
$query = $this->db->get();
?>
<?php foreach($query as $taxexp) : ?>
<td><?php echo $taxexp; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
但是上面的代码不起作用,任何人都可以在这方面帮助我。非常感谢
最佳答案
尝试
foreach ($query->result() as $taxexp){
echo $taxexp->amount;
}
关于php - 如何找出 View 中特定字段的总和 Codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21015132/