html - 表头中的标题不应在 laravel 的 foreach 循环中重复
问题描述
我的观点
<table class="table">
@foreach($students as $student)
<thead>
<tr style="background-color: #e9e5e4;">
<td colspan="4">{{$student->teacher_name}}</td>
</tr>
<tr>
<th> Name </th>
<th> class</th>
<th> subject </th>
</tr>
</thead>
<tbody>
<tr>
<td> {{$student->name }}</td>
<td> {{$student->class}} </td>
<td> {{$student->subject }} </td>
</tr>
</tbody>
@endforeach
</table>
即使教师姓名相同,它也会向我显示多个表,我只想在更改教师姓名时创建新表,否则在同一个表中显示所有记录
解决方案
试试下面的方法:
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Class</th>
<th>Subject</th>
</tr>
</thead>
<tbody>
@foreach($students as $student)
<tr style="background-color: #e9e5e4;">
<td colspan="4">{{$student->teacher_name}}</td>
</tr>
<tr>
<td>{{$student->name }}</td>
<td>{{$student->class}} </td>
<td>{{$student->subject }} </td>
</tr>
@endforeach
</tbody>
</table>
或者
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Class</th>
<th>Subject</th>
<th>Teacher</th>
</tr>
</thead>
<tbody>
@foreach($students as $student)
<tr>
<td>{{$student->name }}</td>
<td>{{$student->class}} </td>
<td>{{$student->subject }} </td>
<td style="background-color: #e9e5e4;">{{$student->teacher_name}}</td>
</tr>
@endforeach
</tbody>
</table>
推荐阅读
- r - 更改表格以将其用于图表
- angular8 - 升级到版本 8 后 Angular 无法导入模块
- c - 将结构从一个列表的末尾移动到另一个列表的开头
- java - Microsoft Graph java Sdk 和 Android 版本的 proguard 问题
- sql - Oracle 中的 REGEXP_REPLACE
- javascript - 如何显示无或块元素取决于javascript上的数字(如风速或温度)?
- ios - 设备无法使用 Firebase 身份验证电话号码
- r - 将日期变成有序变量
- tensorflow - 我已经安装了 tensorflow,但在导入 tensorflow 时仍然遇到错误
- python - 如何在不使用表单的情况下通过 django 中的 html 模板将数据发布到数据库中