php mysql Pivoting table

Ini code nya :

<?php

echo "<table class='table table-striped table-hover table-condensed'>";
echo "<thead>
          <tr>
            <th>No.</th>
            <th>Uraian</th>
            <th>Januari</th>
            <th>Februari</th>
            <th>Maret</th>
            <th>April</th>
            <th>Mei</th>
            <th>Juni</th>
            <th>Juli</th>
            <th>Agustus</th>
            <th>September</th>
            <th>Oktober</th>
            <th>Nopember</th>
            <th>Desember</th>
            <th>Total<br></th>
          </tr>
        </thead>";
echo "<tbody";
echo "<tr>
    <td>A</td>
    <td colspan='14' rowspan='11'>PELAJARAN TERBARU</td>
  </tr>
  <tr>
    <td>A.1</td>
    <td>Pelajaran kpih_k1_kia</td>";
$sql="select descripdatabulanan, 
  SUM(case when month(tanggal) = '1' then value else 0 end) Jan,
  SUM(case when month(tanggal) = '2' then value else 0 end) Feb,
  SUM(case when month(tanggal) = '3' then value else 0 end) Mar,
  SUM(case when month(tanggal) = '4' then value else 0 end) Apr,
  SUM(case when month(tanggal) = '5' then value else 0 end) Mei,
  SUM(case when month(tanggal) = '6' then value else 0 end) Jun,
  SUM(case when month(tanggal) = '7' then value else 0 end) Jul,
  SUM(case when month(tanggal) = '8' then value else 0 end) Ags,
  SUM(case when month(tanggal) = '9' then value else 0 end) Sep,
  SUM(case when month(tanggal) = '10' then value else 0 end) Okt,
  SUM(case when month(tanggal) = '11' then value else 0 end) Nop,
  SUM(case when month(tanggal) = '12' then value else 0 end) Des
from
(
  select id_db, tanggal, kpih_k1_kia value, 'kpih_k1_kia' descripdatabulanan
  from tdatabulanan
  union all
  select id_db, tanggal, kkih_k4_kia value, 'kkih_k4_kia' descripdatabulanan
  from tdatabulanan
  union all
    select id_db, tanggal, pdtk_pn_kia value, 'pdtk_pn_kia' descripdatabulanan
  from tdatabulanan
  union all
    select id_db, tanggal, ppfpk_kia value, 'ppfpk_kia' descripdatabulanan
  from tdatabulanan
  union all
    select id_db, tanggal, kn_kf_kia value, 'kn_kf_kia' descripdatabulanan
  from tdatabulanan
  union all
    select id_db, tanggal, knp_kn1_kia value, 'knp_kn1_kia' descripdatabulanan
  from tdatabulanan
  union all
    select id_db, tanggal, jau15th_kia value, 'jau15th_kia' descripdatabulanan
  from tdatabulanan
  union all
      select id_db, tanggal, pkb_kia value, 'pkb_kia' descripdatabulanan
  from tdatabulanan
  union all
      select id_db, tanggal, jki_kia value, 'jki_kia' descripdatabulanan
  from tdatabulanan
  union all
      select id_db, tanggal, jkb_kia value, 'jkb_kia' descripdatabulanan
  from tdatabulanan
  union all
      select id_db, tanggal, jblh_kia value, 'jblh_kia' descripdatabulanan
  from tdatabulanan
) src
group by descripdatabulanan ORDER BY descripdatabulanan DESC";
$result = mysqli_query($con,$sql);
$i=0;
while($row = mysqli_fetch_array($result)){
    echo "<tr>
    <td>$row[Jan]</td>
           <td>$row[Feb]</td>
           <td>$row[Mar]</td>
           <td>$row[Apr]</td>
           <td>$row[Mei]</td>
           <td>$row[Jun]</td>
           <td>$row[Jul]</td>
           <td>$row[Ags]</td>
           <td>$row[Sep]</td>
           <td>$row[Okt]</td>
           <td>$row[Nop]</td>
           <td>$row[Des]</td>
           <td>Total</td>
           </tr>";
}
echo "
  </tr>
  <tr>
    <td>A.2</td>
    <td>Pelajaran kkih_k4_kia</td>
  </tr>
  <tr>
    <td>A.3</td>
    <td>Pelajaran pdtk_pn_kia</td>
  </tr>
  <tr>
    <td>A.4</td>
    <td>Pelajaran ppfpk_kia</td>
  </tr>
  <tr>
    <td>A.5</td>
    <td>Pelajaran kn_kf_kia</td>
  </tr>
  ";   
echo "</tbody";
echo "</table>";
?>

I want the table as in the picture ? https://lh3.googleusercontent.com/R39JDsRX4zwGPbHNTgwD3JF1M7E1Cyfx7FXFCesYgL52-lhL3w4wiEvpfDOTPmuFTMpRuYyVKeCfLlyRd-_fs_vuAW3SjJtfoy-XplXGykYcF8rFJOJiGgFzr4AuzF0-hhDFoZegr0KOJzTVL2PKsT2oDO0QWpRxvsHx1bRkzZNxwUQHDIDLUEeKJYxgiSMSDN0eZT6TayS644eSO-xWydai8W5KjrzY1NfJ7W2mxiDsf4OEOg5YJjuldW4CeRT4xpw_bHxxCdoZ_NLnLicI1EVVVer1o7afLPB3CYjujzQu3b4LZQqdz2HuEwSz7CXBHMom34Q8N3ZbctLPCq7XvPSWAF3rD42XpmnTk8IDYSmWrc0mmw4q_ltE_Rb5FztdiClkLH4tTqCN9yaOcAKaNet-Ty78Qv6wsVzGfd8Fz779IRwCm00ZFFL5ILgKzD3Nhw64itNtp01arlzEB9aaq94YyFklY-Tq6iUbymKbhcCir247vJjQ4AAk8ffKbsHymMLN5HohDbOlvRCS4g6C2kPliWxojTufusZWRXj3k7sh5PQmt9HlM6BqlyN6W9kaWwsZxY6CoEBA-ESxJ38Iz8eNPwarGnBhcwM–g=w1004-h294-no

TK Ditanyakan on 12 January 2018 pada PHP.
Tambah Komentar
0 Jawaban
  • Jawaban Anda

    Dengan memposting jawaban, anda setuju dengan Kebijakan Privasi dan ketentuan layanan.