我有一个控制器代码:
public function chartService(){
$result["categories"] = array();
$result["series"] = array(
$penjualan = $this->db->Execute("select id_tenant, nama_kantin,
count(id_penjualan) as jumlah_penjualan, sum(total) as total from
kantin_penjualanTenant a join kantin_lokasiKantin b on
a.id_kantin=b.id_kantin group by a.id_tenant,b.nama_kantin");
while ($row = $penjualan->FetchNextObject(false)) {
$result["categories"][]=$row->id_tenant;
$result["nama_kantin"][]=$row->nama_kantin;
$result["series"][0]=
array(
'name' => 'Total Penjualan',
'data' => array((float)$row->total)
);
}
echo json_encode($result);
}
当我尝试运行此代码时,结果是一个数组
'data' => array((float)$row->total)
但实际上,我有11个数据阵列。为什么只显示一个数据数组,而不是11?
试试这个:
$series = array('name' => 'Total Penjualan', 'data' => array());
while ($row = $penjualan->FetchNextObject(false)) {
$result["categories"][]=$row->id_tenant;
$result["nama_kantin"][]=$row->nama_kantin;
array_push($series['data'], (float)$row->total);
}
$result["series"][0] = $series;