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

        $all_hostel_table = "DELETE FROM hostel_table WHERE hosteltable_id=$id";

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

    }

?>
    
            <!-- Recent Sales Start -->
            <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">Hostel Request</h6>
                        
                    </div>
                    <div class="table-responsive">
                      <div class="container">
                        <div class="row">
                            <div class="col-md-12">
                                 <!-- view all hostel_table  -->
                               <table class="table text-start align-middle table-bordered table-hover mb-0" style="margin-top:50px;">
                                    <thead>
                                        <tr>
                                            <th scope="col">S/N</th>
                                            <th scope="col">Surname</th>
                                            <th scope="col">Othername</th>
                                            <th scope="col">Deparment</th>
                                            <th scope="col">Residential Address</th>
                                            <th scope="col">Name of Guardian</th>
                                            <th scope="col">Phone Number: Guardian</th>
                                            <th scope="col">Action</th>
                                            <th scope="col">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                            $all_hostel_table = mysqli_query($db, "SELECT * FROM hostel_table");

                                            // fetch all carry over 
                                            if(mysqli_fetch_array($all_hostel_table)){
                                                
                                                // use foreach loop to echo all data
                                                foreach($all_hostel_table as $hostel){
                                        ?>
                                        <tr>
                                                <td><?php echo $hostel['hosteltable_id']; ?></td>
                                                <td><?php echo $hostel['sname']; ?></td>
                                                <td><?php echo $hostel['othernames']; ?></td>
                                                <td><?php echo $hostel['department_name']; ?></td>
                                                <td><?php echo $hostel['residential_address']; ?></td>
                                                <td><?php echo $hostel['nameguardian']; ?></td>
                                                 <td><?php echo $hostel['phoneall']; ?></td>
                                                  
                                                  
                                                  
                                                  
                                                <td><a class="btn btn-sm btn-success" href="index.php?env=edit_hostel&hosteltable_id=<?php echo $hostel['hosteltable_id']; ?>">Edit</a></td>
                                                <td>
                                                    <form method="POST">
                                                        <input type='hidden' name='delete_hostel' value='<?php echo $hostel['hosteltable_id']; ?>'>
                                                        <input type='submit'class='btn btn-sm btn-danger' name='delete' value='Delete'>
                                                    </form>
                                          
                                                </td>
                                        </tr>
                                        <?php
                                            }
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                      </v>
                    </div>
                </div>
            </div>
            <!-- Recent Sales End -->

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

