<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>View Teachers</title>
    <link rel="stylesheet" href="#">
    <style type="text/css">
        body {
    font-family: Arial, sans-serif;
    margin: 20px;
}

h2 {
    text-align: center;
    margin-bottom: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

table, th, td {
    border: 1px solid #ddd;
}

th, td {
    padding: 12px;
    text-align: left;
}

th {
    background-color: #f2f2f2;
}

a {
    margin-right: 10px;
    text-decoration: none;
    color: #007bff;
}

a:hover {
    text-decoration: underline;
}

    </style>
</head>
<body>
    <div class="container">
        <h2>Teachers List</h2>
        <table>
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Email</th>
                    <th>Subject</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php
                include('db_connection.php');
                $query = "SELECT t.teacher_id, t.name, t.subject, u.email 
                          FROM teachers t 
                          JOIN users u ON t.user_id = u.user_id";
                $result = mysqli_query($conn, $query);
                while ($row = mysqli_fetch_assoc($result)) {
                    echo '<tr>';
                    echo '<td>' . htmlspecialchars($row['name']) . '</td>';
                    echo '<td>' . htmlspecialchars($row['email']) . '</td>';
                    echo '<td>' . htmlspecialchars($row['subject']) . '</td>';
                    echo '<td>
                            <a href="edit_teacher.php?id=' . $row['teacher_id'] . '">Edit</a> |
                            <a href="delete_teacher.php?id=' . $row['teacher_id'] . '" onclick="return confirm(\'Are you sure you want to delete this teacher?\');">Delete</a>
                          </td>';
                    echo '</tr>';
                }
                mysqli_close($conn);
                ?>
            </tbody>
        </table>
    </div>
</body>
</html>
