I am working on a dashboard graphs on a laravel project I have may combo graphs in the dashboard so, i need to have a verygood performance
my problem is the number of statements that i should run to get the graph data from database
for example: i need to get the number of leads per user group by lead source in each month, so i have to run my mysql statements (no of users * number of lead sources * 12) times, this way is very slow and hard
$cash=array();
$users=DB::table('users')->where('deleted','0')->get();
foreach($users as $user){
for($f=1;$f<=12 ;$f++){
if($f<10) $ee='0'.$f; else $ee=$f;
$amount=DB::table('installments')->where('deleted','0')->where('owner',$user->id)->where('status','23')->where(DB::raw('DATE_FORMAT(date, "%Y-%m") '),date("Y-".$ee))->sum("amount");
array_push($cash, $amount);
}
}
i need another way which allow me to get the combo bar charts from database in high performance