請需要幫助...添加陣列
$months = Records::select('payment_month')
->distinct()->where('payment_year',$year)
->where('company_id',$company_id)->get();
foreach ($months as $month) {
$data = Records::select(
DB::raw('SUM(record_db.credits) as credits'),
DB::raw('SUM(record_db.amount) as amount'),
DB::raw('SUM(record_db.totalamount) as totalamt'), 'record_db.payment_month')
->where('record_db.company_id','=',$company_id)
->where('record_db.payment_month','=',$month->payment_month)
->where('record_db.payment_year','=',$year)
->first();
}
return Response::json($data);
上述查詢工作正常,我有January, February and March
月份在數據庫表,但它只返回的March
記錄。
我試圖results[]=$data
但仍然不能正常工作。
你想要什麼結果有什麼呢? –
'一月910 345 657''二月345 980 123''三月214 436 989',這樣的事情... – BlackPearl
檢查我的答案,然後 –