【发布时间】:2017-05-23 16:22:36
【问题描述】:
我有一个数据数组要使用 html 中的表格显示。但是我使用的 foreach 循环没有给出所需的格式。 下面是数组数据
$data = Array
(
[0] => Array
(
[id] => 10
[asset_name] => Mini Paver
[qty] => 3
[est_start_date] => 02/05/2017
[days] => 2
[comments] => Comment 2
[bundle_name] => 1XRoller 1XPaver
)
[1] => Array
(
[id] => 11
[asset_name] => Roller
[qty] => 2
[est_start_date] => 03/07/2018
[days] => 4
[comments] => Comment 2
[bundle_name] => 1XRoller 1XPaver
)
)
我的视图 html 代码:
@foreach($data as $value)
<table class="" style="width: 100%;border:1px solid #ccc">
<thead>
<tr>
<th colspan="4"> <p><?php echo $value['bundle_name'];?> </p></th>
</tr>
<tr>
<th style="text-align: center">id</th>
<th style="width:5%;text-align: center">Asset Category</th>
<th style="width:5%;text-align: center">Days</th>
<th style="width:5%;text-align: center">Qty</th>
</tr>
</thead>
<tbody>
<tr>
<th style="text-align: center"><?php echo $value['id'];?> </th>
<th style="width:5%;text-align: center"><?php echo $value['asset_name'];?></th>
<th style="width:5%;text-align: center"><?php echo $value['days'];?></th>
<th style="width:5%;text-align: center"><?php echo $value['qty'];?></th>
</tr>
</tbody>
</table>
@endforeach
通过使用上面的每个循环,我得到了下面的 html 格式,如 bundle name 正在重复。
这意味着我希望捆绑包名称仅出现一次,其余详细信息应按行显示。 我怎么做 ?请问有什么建议吗? 谢谢。
【问题讨论】:
-
您的 bundle_name 对所有项目都一样吗?还是会有所不同?
标签: laravel foreach laravel-5.4