如何在刀片视图中返回此查询

时间:2018-03-26 16:38:24

标签: laravel

$semester01 = '1';
    $session01 = '5';
    $level01 = '200';


    $results = DB::table('results')
    ->join('departments', 'results.DepartmentID', '=', 'departments.DepartmantID')
    ->join('subjects', 'results.SubjectID', '=', 'subjects.SubjectID')
    ->groupBy('matricno')
    ->selectRaw('results.matricno as matricno, sum(tnu) as sum, sum(subjects.SubjectValue) as sum2')
    ->where('results.Level', $level01)
    ->where('results.Semester', $semester01)
    ->where('results.SessionID', $session01)
    ->where('departments.DepartmantID', '17')
    ->get();




    //return $arrayed;
    $results2 = DB::table('results')
    ->join('departments', 'results.DepartmentID', '=', 'departments.DepartmantID')
    ->join('subjects', 'results.SubjectID', '=', 'subjects.SubjectID')
    ->groupBy('matricno')
    ->selectRaw('results.matricno as matricno, sum(tnu) as sumr2, sum(subjects.SubjectValue) as sum2r2')
    ->where('results.Level', $level01)
    ->where('results.Semester', $semester01)
    ->where('results.SessionID', $session01)
    ->where('departments.DepartmantID', '7')
    ->get();

上述代码应该让一组学生与各个部门一起返回不同的结果。

Result1和result2应该连接在一起,matricno是独立字段。我想以这种形式显示结果。将两个结果合并为一个表格形式。

matricno |总和| sum2 | sumr2 | sum2r2

3 个答案:

答案 0 :(得分:2)

您可以使用merge()方法合并这些集合,例如;

$ merged_result = $ results-> merge($ results2)

答案 1 :(得分:0)

您可以返回包含以下某些数据的视图

return view('viewname', ['results' => $results, 'results2' => $results2]);

答案 2 :(得分:0)

return view('yourview')->with(['results' => $results, 'results2' => $results2]);