2 Foreach Loop Inside A Table

989 Views Asked by At

I had Users table and group table, when i load a group table, it loads the user which have same group_id as the group table id. it works, but my problem is the foreach was quite a mess. the output looks like this.. enter image description here

however, i want to make the output look like this. enter image description here

here is my code..

 <tbody>
     <?php $i = 0; ?>
     @foreach ($auser as $res)
     <?php $i += 1; ?>
     <tr @if($i%2==0) class="bgcolor" @endif>
         <td>{{ $res->id }}.</td>
         <td id="showdet">{{ $res->nama }}</td>
         <td>{{ $res->description }}</td>
         <?php $user = DB::table('users')->where('devgroup',$res->id)->get();?>
         @foreach($user as $mem)
             <td>{{ $mem->name }}</td>
         @endforeach
         <td>
             <a class="default-btn" href="/pms/admin/group/edit/{{ $res->id }}">Edit</a>&nbsp;&nbsp;
             <a type="submit" class="default-btn del" data-id="devgroup" href="#"{{ $res->id }}">Delete</a>
         </td>
     </tr>
     @endforeach
 </tbody>

what did i do wrong? thank you for your help.

1

There are 1 best solutions below

4
On BEST ANSWER

You create new TD for each member. The nested foreach has to be:

<td>
    @foreach($user as $mem)
        {{ $mem->name }}<br>
    @endforeach
</td>

The result will be:

<td>
    Name 1<br>
    Name 2<br>
    Name 3<br>
</td>

I don't know the template engine you used, add inside a loop condition and don't put <br> after the last one member.