我正在尝试获得数组的总值。
foreach ($query->result() as $row)
{
echo $row->amount;
};
而这正在回应普通数字,例如
224 2344 24 2342 123等...
现在我只想回应总价值。
答案 0 :(得分:2)
使用$this->db->select_sum();
例如:
$this->db->select_sum('age');
$query = $this->db->get('members');
// Produces: SELECT SUM(age) as age FROM members
答案 1 :(得分:0)
你可以把它加到一个变量($total
),因为你反正遍历所有元素。
$total = 0;
foreach ($query->result() as $row) {
echo $row->amount;
$total += $row->amount;
};
echo $total;