<?php
include __DIR__ . '/../koneksi.php';
include "inc/navbar.php";

$query = mysqli_query($conn, "
    SELECT santri.*, kelas.nama_kelas
    FROM santri
    LEFT JOIN kelas ON santri.id_kelas = kelas.id_kelas
");
?>


<!DOCTYPE html>
<html>
<head>
    <title>Data Santri</title>
    <link rel="stylesheet" href="admin.css">
</head>
<body>

<div class="wrapper">
    <div class="header">
        <h2>Data Santri</h2>
        <a href="santri_tambah.php" class="btn btn-add">+ Tambah Santri</a>
    </div>

    <table class="table">
        <thead>
            <tr>
                <th>No</th>
                <th>NIS</th>
                <th>Nama</th>
                <th>Jenis Kelamin</th>
                <th>Kelas</th>
                <th>Alamat</th>
                <th>Tahun Masuk</th>
                <th>Aksi</th>
            </tr>
        </thead>
        <tbody>


<?php
$no = 1;
while ($row = mysqli_fetch_assoc($query)) {
?>
<tr>
    <td><?= $no++; ?></td>
    <td><?= $row['nis']; ?></td>
    <td><?= $row['nama']; ?></td>
    <td><?= $row['jenis_kelamin']; ?></td>
    <td><?= $row['nama_kelas']; ?></td>
    <td><?= $row['alamat']; ?></td>
    <td><?= $row['tahun_masuk']; ?></td>
    <td>
        <a href="santri_edit.php?id=<?= $row['id']; ?>" class="btn btn-edit">Edit</a>
        <a href="santri_hapus.php?id=<?= $row['id']; ?>"
           onclick="return confirm('Yakin hapus data ini?')"
           class="btn btn-delete">Hapus</a>
    </td>
</tr>

<?php } ?>
</table>
