如何根据年份和学期对数据进行分组,以便在laravel blade中打印

yzuktlbb  于 2021-09-23  发布在  Java
关注(0)|答案(5)|浏览(357)

我有一个数据,我想根据他们的学年和学期按组打印。在ms access中,我可以使用关系和组报告来实现这一点。我在拉拉维尔做这件事,但我过得很艰难。
这是样品记录
主题代码描述标题LeUnitsGradeCreditSysEMBMATH 01商业数学32.25317-20181stbmath 02投资数学32.0032017-20182ndbuscorbusiness英文通讯32.0032018-20191steco 01土地改革与税收经济学简介31.7532017-20181steco 02微观经济学理论与实践31.7532017-20182ndelec 01项目发展管理31.5032018-20191stelec 09商业道德32.7532019-20201stelec B牧场32.0032019-20201stelec ba 3合作管理31.5032018-20192ndelec ba 5可行性研究31.7532018-20192ndelec ba 6风险管理32.5032019-20201st
我想像这样打印和分组它们
科目代码描述性标题拉德信用

6pp0gazn

6pp0gazn2#

---------bmath 01商业数学2.253eco 01经济学导论
土地改革和税收1.753

whitzsjs

whitzsjs4#

---------bmath 02投资数学2.003eco 02微观经济学理论
和实践1.753
等等等等。
laravel是否可以输出此打印报告?
这是我的控制器:

public function viewTOR($id){

        $student = Student::where('stud_no', $id)->first();

        $grades = DB::table('grades')
        ->distinct()
        ->leftJoin('subjects', function($join)
            {
                $join->on('subjects.subj_code', '=', 'grades.subj_code');

             })
        ->where('grades.student_number', '=', $id)

        ->get();

        //echo "<pre>"; print_r($unitsSum);die;
       return view('admin.grades.viewtor', ['grades'=>$grades,'student'=>$student]);

    }

这是我的刀锉

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="{{url('images/front_images/smmclogo.jpg')}}">

    <title>Transcript of Records</title>

    <link rel="canonical" href="https://getbootstrap.com/docs/4.0/examples/checkout/">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <!-- Bootstrap core CSS -->
    <link href="{{url('css/bootstrap.min.css')}}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="{{url('css/form-validation.css')}}" rel="stylesheet">

<style>
table.bordered{
    border:1px solid black;
    margin-top:20px;
    margin-bottom:20px;
  }
table.bordered > thead > tr > th{
    border:1px solid black;
}
table.bordered > tbody > tr > td{
    border:1px solid black;
}
  </style>

  </head>

  <body class="bg-light" style="font-family:Arial Narrow">

        <div class="col-md-12 order-md-2">
        <h2 class="mb-3 text-center font-weight-bold"  style="color:#1a0dab;font-family:sans-serif;font-weight:900px">SAN MATEO MUNICIPAL COLLEGE</h2>

          <h5 class="mb-3 text-center font-weight-bold"  style="color:#1a0dab;font-family:sans-serif">OFFICE OF THE COLLEGE REGISTRAR</h5>

          <p class="text-center font-weight-bold" style="color:#1a0dab;font-family:sans-serif;font-size:24px">STUDENT'S CHECKLIST</p>

            <p class="text-center font-weight-bold" style="line-height:5px;">(Not Valid for Transfer)</p>
           <BR>
         <div class="row" >
                <div class="column" style="margin-left:40px;width:800px;">
                  <table style="margin-left:20px;width:600px;border:0px">
                    <tr>
                        <td >Student Number:</td>
                        <td style="border-bottom:1px solid"><b>{{ $student->stud_no}}</b></td>
                    </tr>
                    <tr >
                        <td>Name:</td>
                        <td style="border-bottom:1px solid"><b>{{ $student->lastname}}, {{ $student->firstname}} {{ $student->middleinitial}}.</b></td>
                    </tr>
                    <tr >
                        <td>Program:</td>
                        <td style="border-bottom:1px solid"><b>{{ $student->course}}</b></td>
                    </tr>
                  </table>

                </div>
                <div class="column" >

                <table style="margin-left:20px;width:400px;border:0px">
                    <tr >
                        <td>Year Level:</td>
                        <td style="border-bottom:1px solid"><b>{{ $student->year_level}}</b></td>
                    </tr>

                  </table>
                </div>
                </div>
                <br>

            <table class="table-sm bordered" style="margin-left:25px;border:1px solid black">
                            <thead>
                                <tr  class="text-center" style="width:100%;color:#1a0dab;font-weight:BOLD;font-family:Helvetica" >

                                <th scope="col">SUBJECT CODE</th>
                                <th  scope="col">DESCRIPTIVE TITLE</th>

                                <th  scope="col">GRADE</th>
                                <th scope="col">CREDIT</th>

                                </tr>
                            </thead>
                            <tbody >
                            @foreach($grades as $gr)
                                <tr >

                                <td  style="width:15%">{{ $gr->subj_code}}</td>
                                <td  style="width:30%">{{ $gr->subj_desc}}</td>

                                <td class="text-center">{{ $gr->grade}} </td>
                                <td  style="width:10%">{{ $gr->list1}} </td>

                                </tr>
                                @endforeach

                            </tbody>

            </table>

        </div>
      </div>

    </div>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
   <!--  <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery-slim.min.js"><\/script>')</script>-->
    <script src="{{url('js/vendor/popper.min.js')}}"></script>
    <script src="{{url('js/front_js/bootstrap.min.js')}}"></script>
    <script src="{{url('js/vendor/holder.min.js')}}"></script>
    <script>
      // Example starter JavaScript for disabling form submissions if there are invalid fields
      (function() {
        'use strict';

        window.addEventListener('load', function() {
          // Fetch all the forms we want to apply custom Bootstrap validation styles to
          var forms = document.getElementsByClassName('needs-validation');

          // Loop over them and prevent submission
          var validation = Array.prototype.filter.call(forms, function(form) {
            form.addEventListener('submit', function(event) {
              if (form.checkValidity() === false) {
                event.preventDefault();
                event.stopPropagation();
              }
              form.classList.add('was-validated');
            }, false);
          });
        }, false);
      })();
    </script>
  </body>
</html>

laravel是否有其他方法或功能可以实现这一点。非常感谢你。。

dgjrabp2

dgjrabp25#

我就是这样做的:

$grades = $grades->groupBy(function($grade) {
  return $grade->sy.' '.$grade->sem;
})->sortKeys();
<table class="table">
    <thead>
        <tr>
            <th>SUBJECT CODE</th>
            <th>DESCRIPTIVE TITLE</th>
            <th>GRADE</th>
            <th>CREDIT</th>
        </tr>
    </thead>
    <tbody>
        @foreach($grades as $sysem => $semgrades)
            <tr><th colspan="4" style="text-align:center;">{{ $sysem }}</th></tr>
            @foreach($semgrades as $grade)
                <tr>
                    <td>{{ $grade->subj_code }}</td>
                    <td>{{ $grade->descriptive_title }}</td>
                    <td>{{ $grade->subj_desc }}</td>
                    <td>{{ $grade->list1 }}</td>
                </tr>
            @endforeach
        @endforeach
    </tbody>
</table>

相关问题