<DOCTYPE html>
    <html lang="en">

    <head>
        <div class="topnav">
            <a href=" halaman_admin.php">Beranda</a>
            <a class="active" href=" datapesertaadm.php">Data Peserta</a>
            <a href="latihanadm.php">Latihan</a>
            <a href="datalombaadm.php">Lomba</a>
            <a href="dataraportadm.php">Nilai</a>
            <a href="approveva.php">Approve VA</a>
        </div>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" type="text/css" href="../style.css">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css">
    </head>

    <body>
        <?php
        session_start();

        if ($_SESSION['status'] == "") {
            header("location:../loginpageadmin.php?pesan=gagal");
        }

        ?>
        <div class="container">
            <br>
            <h2>Daftar Peserta</h2>
            <a class="btn btn-primary" href=" tambahpesertaadm.php" role="button">Tambah Peserta</a>
            <br>
            <table class="table" style="text-align:center">
                <thead>
                    <tr>
                        <th>Nomor</th>
                        <th>Nama</th>
                        <th>Anak-ke</th>
                        <th>Jumlah Saudara</th>
                        <th>NIS</th>
                        <th>Jenjang</th>
                        <th>Jenis Kelamin</th>
                        <th>Agama</th>
                        <th>No.Peserta</th>
                        <th>No.Ortu</th>
                        <th>Tanggal Lahir</th>
                        <th>Tempat Lahir</th>
                        <th>Alamat</th>
                        <th>Tingkatan</th>
                        <th>Asal Sekolah</th>
                        <th>Nomor VA</th>
                        <th>Opsi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $servername = "localhost";
                    $username = "root";
                    $password = "";
                    $database = "membership";

                    $connection = new mysqli($servername, $username, $password, $database);

                    if ($connection->connect_error) {
                        die("Gagal Koneksi" . $connection->connect_error);
                    }

                    $sql = "SELECT * FROM peserta WHERE cad4='1'";
                    $result = $connection->query($sql);

                    if (!$result) {
                        die("Invalid query: " . $connection->error);
                    }

                    while ($row = $result->fetch_assoc()) {
                        echo "
                        <tr>
                        <td>$row[id]</td>
                        <td>$row[nama_peserta]</td>
                        <td>$row[nis]</td>
                        <td>$row[anakke]</td>
                        <td>$row[jmlhsdr]</td>
                        <td>$row[jenjang]</td>
                        <td>$row[jenis_kelamin]</td>
                        <td>$row[agama]</td>
                        <td>$row[tgl_lahir]</td>
                        <td>$row[tmpt_lahir]</td>
                        <td>$row[nomorpeserta]</td>
                        <td>$row[nomorortu]</td>
                        <td>$row[alamat]</td>
                        <td>$row[tingkatan]</td>
                        <td>$row[asalsekolah]</td>
                        <td>$row[virtualacc]</td>
                        <td><a class='btn btn-primary btn-sm' href=' editpesertaadm.php?id=$row[id]'>Edit</a></td>
                        <td><a class='btn btn-danger btn-sm' href=' hapuspesertaadm.php?id=$row[id]'>Delete</a</td>
                    </tr>
                        ";
                    }
                    ?>

                </tbody>
            </table>
        </div>
    </body>

    </html>