如何总计每行中的数字

时间:2017-10-09 06:53:19

标签: php mysql database laravel

db table

enter image description here

在数据库示例图片中,我如何总计列中的数字 例如:9 + 2 + 1 + 1 + ..... = ??

public function graph()
  {
    $statistics = DiraStatistics::all();
    $labels = [];
    $data = [];
    $data1 = [];
    $data2 = [];
    $data3 = [];
    foreach ($statistics as $key => $statistic) {
        array_push($labels,$statistic->date_access);
        array_push($data,$statistic->question_asked);
        array_push($data1,$statistic->low_confidence);
        array_push($data2,$statistic->no_answer);
        array_push($data3,$statistic->missing_intent);
    }
     return view('AltHr.Chatbot.graph', compact('labels','data','data1','data2','data3'));
  }

我打电话给表格

1 个答案:

答案 0 :(得分:2)

请使用以下代码检索总和

public function graph()
{
    $statistics = DiraStatistics::all();
    $question_asked_sum = $statistics->sum('question_asked');
    $labels = $statistics->pluck('date_access');
    $data = $statistics->pluck('question_asked');
    $data1 = $statistics->pluck('low_confidence');
    $data2 = $statistics->pluck('no_answer');
    $data3 = $statistics->pluck('missing_intent');
    return view('AltHr.Chatbot.graph', compact('labels','data','data1','data2','data3', 'question_asked_sum'));
}