<?php
include '../../config/conn.php';
$date = date('Y-m-d');
if (!isset($_GET['tampildata'])) {
    $N = "Keseluruhan";
} else {
    $N = $_GET['tampildata'];
}
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=Data Santri PONDOK $N.xls");
?>

<table id="datatable" class="table table-striped table-bordered">
    <thead>
        <tr>
            <td colspan="10" align="center" style="font-size: x-large;">DATA SANTRI
                <?php echo $N; ?></td>
        </tr>
    </thead>
    <thead>
        <tr>
            <th width="50">No</th>
            <th>ID santri</th>
            <!--<th>No Rekening</th>-->
            <th>Nama</th>
            <th>Tempat lahir</th>
            <th>Tanggal lahir</th>
            <th>Jenis Kelamin</th>
            <th>Alamat</th>
            <th>NIK</th>
            <th>NO.KK</th>
            <th>Nama Ayah</th>
            <th>Nama Ibu</th>
            <th>No. HP</th>
            <th>Status</th>
            <th>Tanggal Masuk</th>

        </tr>
    </thead>
    <tbody>
        <?php
        $no = 0;
        //sort data
        if (!isset($_GET['tampildata']) or $_GET['tampildata'] == 0) {
            //bukan data sorting
            $query = mysqli_query($conn, "SELECT * FROM santri ORDER BY nama");
            $th = "";
        } else {
            $query = mysqli_query($conn, "SELECT * FROM santri WHERE YEAR(tanggal_masuk)=$_GET[tampildata] ORDER BY nama");
            $th = "?th=$_GET[tampildata]";
        }
        while ($row = mysqli_fetch_array($query)) {
            $no++;
        ?>
            <tr>
                <td><?php echo $no; ?></td>
                <td><?php echo $row['id_santri']; ?></td>
                <!--<td><?php //echo $row['no_rekening'];
                        ?></td>-->
                <td><?php echo $row['nama']; ?></td>
                <td><?php echo $row['tempat_lahir']; ?></td>
                <td><?php echo $row['tanggal_lahir']; ?></td>
                <td><?php if ($row['jenkel'] == "l") {
                        echo "Laki-laki";
                    } else {
                        echo "Perempuan";
                    } ?>
                </td>
                <td><?php echo $row['alamat']; ?></td>
                <td><?php echo "'" . $row['nik_santri']; ?></td>
                <td><?php echo "'" . $row['no_kk']; ?></td>
                <td><?php echo $row['nama_ayah']; ?></td>
                <td><?php echo $row['nama_ibu']; ?></td>
                <td><?php echo "'" . $row['no_hp']; ?></td>
                <td><?php $kueri  = mysqli_query($conn, "SELECT * FROM jenis_status WHERE id_status='$row[statuus]' order by id_status asc");
                    while ($data = mysqli_fetch_array($kueri)) {
                        echo "$data[nama_status]";
                    } ?></td>
                <td><?php echo $row['tanggal_masuk']; ?></td>
            </tr>
        <?php } ?>
    </tbody>
</table>

<br><br><br><br>
Data <?php echo date('d-m-Y') . "  " . date('H:i:s'); ?>