<?php
    include "../inc/koneksi.php";
    $tanggal = date("d/m/y");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>LAPORAN DATA KARTU KELUARGA</title>
</head>
<body>
    <center>
        <h2>PEMERINTAH KABUPATEN PERCONTOHAN</h2>
        <h3>KECAMATAN PERCONTOHAN <br> DESA PERCONTOHAN</h3>
        <p>________________________________________________________________________</p>
        <h3>LAPORAN DATA KARTU KELUARGA</h3>
        <p align="left">Dicetak Tanggal : <?php echo $tanggal; ?></p>
    </center>

    <table border="1" cellspacing="0" style="width: 100%">
        <thead>
            <tr>
                <th>No</th>
                <th>No KK</th>
                <th>Kepala Keluarga</th>
                <th>Alamat</th>
                <th>Anggota</th>
            </tr>
        </thead>
        <tbody>
            <?php
            $no=1;
            $sql_tampil = "SELECT k.no_kk, k.kepala, k.desa, k.rt, k.rw, k.kec, k.kab, k.prov, COUNT(a.id_anggota) as jumlah 
                          FROM tb_kk k LEFT JOIN tb_anggota a ON k.id_kk = a.id_kk 
                          GROUP BY k.id_kk";
            $query_tampil = mysqli_query($koneksi, $sql_tampil);
            while ($data = mysqli_fetch_array($query_tampil,MYSQLI_BOTH)) {
            ?>
            <tr>
                <td align="center"><?php echo $no++; ?></td>
                <td>'<?php echo $data['no_kk']; ?></td>
                <td><?php echo $data['kepala']; ?></td>
                <td><?php echo $data['desa']; ?>, RT <?php echo $data['rt']; ?>/ RW <?php echo $data['rw']; ?></td>
                <td align="center"><?php echo $data['jumlah']; ?> Orang</td>
            </tr>
            <?php } ?>
        </tbody>
    </table>

    <script>
        window.print();
    </script>
</body>
</html>
