<?php

function getTeacherForSubject($conn, $subject_id) {

    $stmt = $conn->prepare("
        SELECT t.teacher_id
        FROM teachers t
        JOIN teacher_subject ts ON ts.teacher_id = t.teacher_id
        WHERE ts.subject_id = ?
        LIMIT 1
    ");

    $stmt->bind_param("i", $subject_id);
    $stmt->execute();

    return $stmt->get_result()->fetch_assoc();
}