我在数据库中存储数量的值(int)。我需要通过将所有行总计加在一起来计算总数量。 $ this-> db-> count_all_results()的问题是它返回的是总行数,但不计算所有存储的值。任何帮助将非常感激。用Codeigniter Active Record计算行总数
function currentDealTotalQuantity($id)
{
$this->db->select('quantity');
$this->db->from('table');
$this->db->where('id', $id);
$total_sold = $this->db->count_all_results();
if ($total_sold > 0)
{
return $total_sold;
}
return NULL;
}
收到此错误:类CI_DB_mysql_result的对象无法转换成int – undertokyo
编辑。现在请尝试这个。 –
就是这样!谢谢。 – undertokyo