Html 如何将循环拆分为多个列和行?
我有一个循环以表格格式显示数据Html 如何将循环拆分为多个列和行?,html,laravel,loops,Html,Laravel,Loops,我有一个循环以表格格式显示数据 <table> <thead> <th>name</th> <th>qty</th> </thead> <tbody> @foreach ($users as $user) @foreach ($user->displayDetails($user->id) as $d) <tr> <td&
<table>
<thead>
<th>name</th>
<th>qty</th>
</thead>
<tbody>
@foreach ($users as $user)
@foreach ($user->displayDetails($user->id) as $d)
<tr>
<td>{{$d->name}}</td>
<td>{{$d->ordered_qty}}</td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
我期待的是:
name | qty name | qty
John 1 Lynn 1
Jack 2
我怎样才能做到这一点呢?你可以使用这样的方法:(这是一种HTML拆分,而不是Laravel)
名称
数量
名称
数量
@foreach($user as$key=>$user)
@foreach($user->displayDetails($user->id)作为$d)
{{$d->name}
{{$d->订购数量}
@endforeach
@如果((@key+1)%2==0)
@恩迪夫
@endforeach
最多可以有多少列?2? 无限的?字母表中的每个字母对应一个?你想要并排排列吗??如果有数量为1的另一条记录,您已经发表了评论,但尚未选择任何答案。您的预期结果为否sense@btl是的,不受限制,只要有数据。但对于右侧,它将显示从第2行开始的数据。我更新了修改时使用的索引。
name | qty name | qty
John 1 Lynn 1
Jack 2
<table>
<thead>
<th>name</th>
<th>qty</th>
<th>name</th>
<th>qty</th>
</thead>
<tr>
@foreach ($users as $key => $user)
@foreach ($user->displayDetails($user->id) as $d)
<td>{{$d->name}}</td>
<td>{{$d->ordered_qty}}</td>
@endforeach
@if((@key + 1) % 2 == 0)
</tr><tr>
@endif
@endforeach
</tr>
</table>