【问题标题】:HTML : How to merge rowspan if have a looping?HTML:如果有循环,如何合并行跨度?
【发布时间】:2018-04-01 10:14:16
【问题描述】:

我有一个关于创建表的问题。

我想这样做:

但我得到了这个:

我已经尝试了所有方法,但我意识到循环存在问题。我尝试将@endforeach 放在</tr> 之前。但是桌子看起来更乱了。

这是我的代码

<div class="col-md-12 text-center">
  <div class="datagrid">
    <table class="table table-hover">
      <thead>
        <tr>
          <th>No</th>
          <th>Booking ID</th>
          <th>Name</th>
          <th>Identity</th>
          <th>Diver Status</th>
          <th>Status</th>
          <th>Payment</th>

        </tr>
      </thead>
      <tbody>
        @foreach($report->bookings as $booking)

        <tr>
          <td class="border" rowspan="{{count($booking->divers)}}">{{ $loop->index+1 }}</td>
          <td rowspan="{{count($booking->divers)}}">{{$booking->booking_id}}</td>

          @foreach($booking->divers as $diver)
          <td>{{$diver->name}}</td>
          <td>{{$diver->identity}}</td>
          <td>{{$diver->license}}</td>
          <td rowspan="{{count($diver->name)}}">{{$booking->status }}</td>
          <td rowspan="{{count($diver->name)}}">{{ $booking->total_fee }}</td>
        </tr>
        @endforeach
        @endforeach


      </tbody>
    </table>
  </div>
</div>

我想如何将状态和付款与 no 和 booking id 合并?

【问题讨论】:

    标签: html loops html-table row


    【解决方案1】:

    我刚好遇到同样的问题,按如下方式完成。

    <tbody>
        @foreach($report->bookings as $booking)
        <tr>
          <td class="border" rowspan="{{count($booking->divers) + 1}}">{{ $loop->index+1 }}</td>
          <td rowspan="{{count($booking->divers) + 1}}">{{$booking->booking_id}}</td>
        </tr>
          <?php $x = ''; ?>
          @foreach($booking->divers as $diver)
            <tr>
                <td>{{$diver->name}}</td>
                <td>{{$diver->identity}}</td>
                <td>{{$diver->license}}</td>
    
              <?php if(empty($x)){?>
                    <td rowspan="{{count($diver->name)}}">{{$booking->status }}</td>
                    <td rowspan="{{count($diver->name)}}">{{ $booking->total_fee }}</td>
              <?php } ?>
    
            </tr>
          <?php $x = $booking->booking_id; ?>
          @endforeach
        @endforeach
    

    如果你已经完成了,请与我分享。 我认为这不是最好的方法。

    【讨论】:

      猜你喜欢
      • 2015-04-19
      • 2022-08-23
      • 2014-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      相关资源
      最近更新 更多