区别如下
row_array返回的为一维数组
result_array返回的为二维数组
/*
*根据起始日期和类型得到总数量和总金额
*/
public function group_by_date_type($sdate,$edate,$ype){
$this->db->select("IFNULL(sum(num),'0') as total,IFNULL(count(num),'0') as num");
$this->db->from('t_b');
if($sdate != 0){
$this->db->where("DATE_FORMAT(date,'%Y-%m-%d')>=",$sdate);
}
if($edate != 0){
$this->db->where("DATE_FORMAT(date,'%Y-%m-%d')<=",$edate);
}
if(!empty($type)){
$this->db->where_in('t_b.type',$ype);
}
$this->db->where('b_del=0');
$query = $this->db->get();
return $query->row_array();//标记值1
}
路上标记值 若返回时的数组 且为$sum[]
要使用到$sum['total']
或$sum['num']
时
使用row_array()则可以直接使用
使用result_array() 则需要改为$sum[0]['total']``$sum[0]['num']