php - Create laravel blade table view that -
i have laravel db::query give me result this
arrayresult = array('nip' => '12345678', 'nama' => 'rachmat', 'month' => '1', 'sum' => 13'), array('nip' => '12345678', 'nama' => 'rachmat', 'month' => '3', 'sum' => 10'), array('nip' => '12345678', 'nama' => 'rachmat', 'month' => '8', 'sum' => 9'));
then create multidimensional array this
foreach ($pegawai $key ) { $peg[$key->nip]['nama'] = $key->nama; $peg[$key->nip]['nip'] = $key->nip; $peg[$key->nip]['month'][$key->month] = $key->sum; }
the result of array this
array(12345678 ('nama' => 'rachmat', 'nip' => '12345678', month(1 => 13, 3 => 10, 8 => 9)));
then view in blade table :
@foreach($peg $st) <tr> <td style="text-align: center;">{{$no++}}</td> <td>{{$st['nama']}}<br>{{$st['nip']}}</td> @foreach($st['bulan'] $a => $value) <td style="text-align: center;"> {{ $value }} </td> @endforeach </tr> @endforeach
the problem $value data shown in sequence, not in accordance month of data.
my view :
<table id="table" class="table table-striped table-bordered table-hover" > <thead> <tr class="tableheader"> <th style="width:10px" rowspan="2" style="text-align: center; vertical-align: middle;">#</th> <th rowspan="2" style="text-align: center; vertical-align: middle;">nama pegawai</th> <th colspan="12" style="text-align: center;">bulan</th> </tr> <tr> <th style="text-align: center;">january</th> <th style="text-align: center;">february</th> <th style="text-align: center;">march</th> <th style="text-align: center;">april</th> <th style="text-align: center;">may</th> <th style="text-align: center;">june</th> <th style="text-align: center;">july</th> <th style="text-align: center;">august</th> <th style="text-align: center;">sept</th> <th style="text-align: center;">okt</th> <th style="text-align: center;">nop</th> <th style="text-align: center;">dec</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">1</td> <td>rachmat<br>123456</td> <td style="text-align: center;"> 13 </td> <td style="text-align: center;"> 10 </td> <td style="text-align: center;"> 9 </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> </tr> </tbody> </table>
what want :
<table id="table" class="table table-striped table-bordered table-hover" > <thead> <tr class="tableheader"> <th style="width:10px" rowspan="2" style="text-align: center; vertical-align: middle;">#</th> <th rowspan="2" style="text-align: center; vertical-align: middle;">nama pegawai</th> <th colspan="12" style="text-align: center;">bulan</th> </tr> <tr> <th style="text-align: center;">january</th> <th style="text-align: center;">february</th> <th style="text-align: center;">march</th> <th style="text-align: center;">april</th> <th style="text-align: center;">may</th> <th style="text-align: center;">june</th> <th style="text-align: center;">july</th> <th style="text-align: center;">august</th> <th style="text-align: center;">sept</th> <th style="text-align: center;">okt</th> <th style="text-align: center;">nop</th> <th style="text-align: center;">dec</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">1</td> <td>rachmat<br>123456</td> <td style="text-align: center;"> 13 </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> 10 </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> 9 </td> </tr> </tbody> </table>
all appriciated
try one
@foreach($peg $st) <tr> <td style="text-align: center;">{{$no++}}</td> <td>{{$st['nama']}}<br>{{$st['nip']}}</td> @for($i = 1, $i <= 12, $i++) <td style="text-align: center;"> {{ isset($st['month'][$i]) ? $st['month'][$i] : "" }} </td> @endfor </tr> @endforeach
Comments
Post a Comment