<?php
    if(isset($_POST['delete'])){
        $id = $_POST['delete_student'];

        $all_student = "DELETE FROM portal WHERE student_id=$id";

        if($db->query($all_student) == TRUE){
            echo "<script>alert('Student Deleted')</script>";
        }else{
            echo "<script>alert('Student not deleted')</script>";
        }

    }

?>
            <!-- Display Student List -->
            <div class="container-fluid pt-4 px-4">
                <div class="bg-secondary text-center rounded p-4">
                    <div class="d-flex align-items-center justify-content-between mb-4">
                        <h6 class="mb-0">All NID Marine Engineering Students</h6>
                        
                    </div>
                    <div class="table-responsive">
                        <table class="table text-start align-middle table-bordered table-hover mb-0">
                            <thead>
                                <tr class="text-white">
                                    <th scope="col"><input class="form-check-input" type="checkbox"></th>
                                    <!--<th scope="col">S/N</th>-->
                                    <th scope="col">Surname</th>
                                    <th scope="col">First Name</th>
                                    <th scope="col">Matric Number</th>
                                    <th scope="col">Program Type</th>
                                    <th scope="col">Department</th>
                                    <th scope="col">Action</th>
                                    <th scope="col">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $all_student = mysqli_query($db, "SELECT * FROM portal WHERE Dept = 'NID Marine Engineering'");

                                // fetch all student 
                                if(mysqli_fetch_array($all_student)){

                                    // use foreach to echo all datas
                                    foreach($all_student as $student){

                                ?>
                                <tr>
                                    <td><input class="form-check-input" type="checkbox"></td>
                                    <!--<td><?php echo $student['student_id']; ?></td>-->
                                    <td><?php echo $student['sname']; ?></td>
                                    <td><?php echo $student['fname']; ?></td>
                                    <td><?php echo $student['mat']; ?></td>
                                    <td><?php echo $student['program']; ?></td>
                                    <td><?php echo $student['Dept']; ?></td>
                                    <td><a class="btn btn-sm btn-success" href="index.php?env=edit_student&student_id=<?php echo $student['student_id']; ?>" target="_self">Edit</a></td>   
                                    
                                    <td>
                                        <form method="POST">
                                            <input type='hidden' name='delete_student' value='<?php echo $student['student_id'] ?>'>
                                            <input type='submit'class='btn btn-sm btn-danger' name='delete' value='Delete'>
                                        </form>
                                  
                                    </td>
                                </tr>

                                <?php
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <!-- Recent Sales End -->

            <!-- Footer Start -->
            <?php include("inc/footer.php"); ?>