gpt4 book ai didi

php - 如何找出 View 中特定字段的总和 Codeigniter

转载 作者:行者123 更新时间:2023-11-30 00:50:35 24 4
gpt4 key购买 nike

我想显示来自数据库的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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com