简体   繁体   中英

Show data in view blade laravel

I have query :

$data = DB::select('SELECT YEAR(start_date) AS Year, 
      count(activity) AS qty,managing FROM data_xxx GROUP 
       BY(start_date),managing');

and called it in "result" view :

<div class="col-md-6">
          <div class="box">
            <div class="box-header with-border">
              <h3 class="box-title">Statistik Realisasi Kerjasama</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <table class="table table-bordered">
                <tr>

    <th>Name</th>
    <th>2019</th>
    <th>2020</th>
    <th>2021</th>
</tr>
<tr>
@foreach($data as $jj)

    <td>{{$jj->managing}}</td>
    <td>{{$jj->year == 2019 ? $jj->qty : ''}} </td>
    <td>{{$jj->year == 2020 ? $jj->qty : ''}} </td>
    <td>{{$jj->year == 2021 ? $jj->qty : ''}} </td>
@endforeach
</tr>
              </table>
            </div>
            <!-- /.box-body -->
            <div class="box-footer clearfix">
              <ul class="pagination pagination-sm no-margin pull-right">
                <li><a href="#">&laquo;</a></li>
                <li><a href="#">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
                <li><a href="#">&raquo;</a></li>
              </ul>
            </div>
          </div>

        </div>

result :

在此输入图像描述

how to echo it in blade so it become like this :

在此输入图像描述

"2019,2020,2021" data from YEAR(start_date) AS Year

"data1 and data2" from managing

"1" from count(activity) AS qty

Just replace this:

<tr>
    <th>Name</th>
    <th>2019</th>
    <th>2020</th>
    <th>2021</th>
</tr>
<tr>
@foreach($data as $jj)

    <td>{{$jj->managing}}</td>
    <td>{{$jj->year == 2019 ? $jj->qty : ''}} </td>
    <td>{{$jj->year == 2020 ? $jj->qty : ''}} </td>
    <td>{{$jj->year == 2021 ? $jj->qty : ''}} </td>
@endforeach
</tr>

with this:

<tr>
    <th>#</th>
    <th>Name</th>
    <th>2019</th>
    <th>2020</th>
    <th>2021</th>
</tr>
@foreach($data as $key => $jj)
<tr>
    <td>{{$key+1}}</td>
    <td>{{$jj->managing}}</td>
    <td>{{$jj->year == 2019 ? $jj->qty : ''}} </td>
    <td>{{$jj->year == 2020 ? $jj->qty : ''}} </td>
    <td>{{$jj->year == 2021 ? $jj->qty : ''}} </td>
</tr>
@endforeach

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM