Tuesday, May 23, 2017

foreach loop inside html table design in laravel

I have an array of data to display using table in html .but the foreach loop which i m using is not giving the desired format . Below is the array data

$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
        )
)

my view html code :

@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

By using above for each loop i m getting the below html format like bundle name is repeating .enter image description here

But i need the output should be like as below : enter image description here

that means i want the bundle name shluld come only one time and the rest of details should display as in rows . How do i do that ? any suggestions please ? Thank you .



via 5367683

Advertisement