Codeigniter Select_Sum 返回“数组”而不是数值?

Jon*_*ork 0 php mysql arrays select codeigniter

我需要将所有行相加以获得结果。使用 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();
}
Run Code Online (Sandbox Code Playgroud)

这是控制器

    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);
}
Run Code Online (Sandbox Code Playgroud)

这是视图的相关代码

<?php echo $Dues_Paid_Tot; ?>
Run Code Online (Sandbox Code Playgroud)

问题是,我在视图中看到的是“Array”,而不是显示 Dues_Paid 列中所有条目的总和。

我哪里出错了?

谢谢!

jon*_*ohn 5

它仍然是一个查询,所以您仍然必须处理结果,尝试将您的模型更改为这个......

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;
}
Run Code Online (Sandbox Code Playgroud)