我需要将所有行相加以获得结果。如下使用select_sum
这是模型
function Dues_Paid_Tot($date)
{
$query = $this->db->select_sum('Dues_Paid', 'Dues_Paid_Tot');
$query = $this->db->get('Membership');
return $query->result();
}
这是 Controller
function Fiscal2()
{
$date = $this->input->post('Select_Date');
if($query = $this->report_model->fiscal_list($date))
{
$data['records'] = $query;
}
$data['date'] = $this->input->post('Select_Date');
$data['Dues_Paid_Tot'] = $this->report_model->Dues_Paid_Tot($date);
$data['main_content'] = 'report_fiscal_view';
$this->load->view('includes/template', $data);
}
这是 View 的相关代码
<?php echo $Dues_Paid_Tot; ?>
问题是,我没有显示 Dues_Paid 列中所有条目的总和,而是在我的 View 中显示“Array”。
我哪里错了?
谢谢!
最佳答案
它仍然是一个查询,因此您仍然需要处理结果,请尝试将您的模型更改为此...
function Dues_Paid_Tot($date)
{
$query = $this->db->select_sum('Dues_Paid', 'Dues_Paid_Tot');
$query = $this->db->get('Membership');
$result = $query->result();
return $result[0]->Dues_Paid_Tot;
}
关于php - Codeigniter Select_Sum 返回 "array"不是数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6338256/