<?php
include 'db_connection.php';

$result = $conn->query("
    SELECT 
        t.name AS teacher_name,
        s.subject_name
    FROM teacher_subject ts
    JOIN teachers t ON ts.teacher_id = t.teacher_id
    JOIN subject s ON ts.subject_id = s.subject_id
    ORDER BY t.name
");
?>

<h2>Teacher - Subject Assignments</h2>

<table border="1" cellpadding="10">
    <tr>
        <th>Teacher</th>
        <th>Subject</th>
    </tr>

    <?php while($row = $result->fetch_assoc()): ?>
    <tr>
        <td><?php echo $row['teacher_name']; ?></td>
        <td><?php echo $row['subject_name']; ?></td>
    </tr>
    <?php endwhile; ?>
</table>