按输入值分组 laravel blade 模板 table
Groups laravel blade template table by input value
我有这样显示的数据库:
<table class="table table-bordered table-striped" id="datatable-default">
<thead>
<tr>
<th>Semester</th>
<th>Kode MTK</th>
<th>Nama Mata Kuliah</th>
<th>Status TM</th>
<th>Kode Bahan Ajar</th>
</tr>
</thead>
@if(!empty($caripaketsemester))
<tbody>
@foreach($caripaketsemester as $key => $row)
<tr class="gradeX">
<td><center><?php echo $row->semester ?></center></td>
<td><center><?php echo $row->kode_mtk ?></center></td>
<td><center><?php echo $row->nama_mtk ?></center></td>
<td><center><?php echo $row->status_tm ?></center></td>
<td><center><?php echo $row->kode_bahan_ajar ?></center></td>
</tr>
@endforeach
</tbody>
@else
<tbody>
<tr class="gradeX">
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
</tr>
</tbody>
@endif
</table>
问题:我想将 table 按 "semester" 分组。我该怎么做?
我想成为这样的人:
Semester 6: Kode MTK | Nama Mata Kuliah | Status TM | Kode Bahan Ajar
Semester 8: Kode MTK | Nama Mata Kuliah | Status TM | Kode Bahan Ajar
*每学期一个table
这将是一些类似的东西...
您需要 return 来自数据库的实际学期,而不仅仅是一组数字。但是你明白了
<?php $semesters = array("1","2","3","4","5","6","7","8","9");?>
@foreach($semesters as $s)
// Loop through semesters array and display a table for each
// Notice I give each table a unique ID. You wouldn't ba allowed to have database-default for all. As ID's must be unique
<table class="table table-bordered table-striped" id="semester-{{$s}}">
<thead>
<tr>
<th>Semester</th>
<th>Kode MTK</th>
<th>Nama Mata Kuliah</th>
<th>Status TM</th>
<th>Kode Bahan Ajar</th>
</tr>
</thead>
<tbody>
@if(!empty($caripakesemester))
// Loop through your data, and check semester value against $row->semester
// Display if matches
@foreach($caripakesemester as $key=>$row)
@if($row->semester == $s)
<tr class="gradeX">
<td><center>{{$row->semester}}</center></td>
<td><center>{{$row->kode_mtk}}</center></td>
<td><center>{{$row->nama_mtk}}</center></td>
<td><center>{{$row->status_tm}}</center></td>
<td><center>{{$row->kode_bahan_ajar}}</center></td>
</tr>
@endif
@endforeach
@else
<tr class="gradeX">
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
</tr>
@endif
</tbody>
</table>
@endforeach
我有这样显示的数据库:
<table class="table table-bordered table-striped" id="datatable-default">
<thead>
<tr>
<th>Semester</th>
<th>Kode MTK</th>
<th>Nama Mata Kuliah</th>
<th>Status TM</th>
<th>Kode Bahan Ajar</th>
</tr>
</thead>
@if(!empty($caripaketsemester))
<tbody>
@foreach($caripaketsemester as $key => $row)
<tr class="gradeX">
<td><center><?php echo $row->semester ?></center></td>
<td><center><?php echo $row->kode_mtk ?></center></td>
<td><center><?php echo $row->nama_mtk ?></center></td>
<td><center><?php echo $row->status_tm ?></center></td>
<td><center><?php echo $row->kode_bahan_ajar ?></center></td>
</tr>
@endforeach
</tbody>
@else
<tbody>
<tr class="gradeX">
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
</tr>
</tbody>
@endif
</table>
问题:我想将 table 按 "semester" 分组。我该怎么做?
我想成为这样的人:
Semester 6: Kode MTK | Nama Mata Kuliah | Status TM | Kode Bahan Ajar
Semester 8: Kode MTK | Nama Mata Kuliah | Status TM | Kode Bahan Ajar
*每学期一个table
这将是一些类似的东西...
您需要 return 来自数据库的实际学期,而不仅仅是一组数字。但是你明白了
<?php $semesters = array("1","2","3","4","5","6","7","8","9");?>
@foreach($semesters as $s)
// Loop through semesters array and display a table for each
// Notice I give each table a unique ID. You wouldn't ba allowed to have database-default for all. As ID's must be unique
<table class="table table-bordered table-striped" id="semester-{{$s}}">
<thead>
<tr>
<th>Semester</th>
<th>Kode MTK</th>
<th>Nama Mata Kuliah</th>
<th>Status TM</th>
<th>Kode Bahan Ajar</th>
</tr>
</thead>
<tbody>
@if(!empty($caripakesemester))
// Loop through your data, and check semester value against $row->semester
// Display if matches
@foreach($caripakesemester as $key=>$row)
@if($row->semester == $s)
<tr class="gradeX">
<td><center>{{$row->semester}}</center></td>
<td><center>{{$row->kode_mtk}}</center></td>
<td><center>{{$row->nama_mtk}}</center></td>
<td><center>{{$row->status_tm}}</center></td>
<td><center>{{$row->kode_bahan_ajar}}</center></td>
</tr>
@endif
@endforeach
@else
<tr class="gradeX">
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
<td><center> </center></td>
</tr>
@endif
</tbody>
</table>
@endforeach