如何解决表头中的标题不应在 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>
即使老师姓名相同,它也会显示多个表,我只想在更改老师姓名时创建新表,否则将所有记录显示在同一个表中
解决方法
你把循环放错了。试试这个
def average(x):
return sum(x) / len(x)
def final_list(lists):
return [average(x) for x in lists]
,
试试以下方法:
<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>
OR
<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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。