<?php
    //this file is used to get school name based on the class id
    $classID = $_REQUEST['q'];
    include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");
    $schoolName = "Not-Found";
    $schoolID = 0;
    $result = $conn->query("SELECT * FROM school_class WHERE class_id = '$classID'");
    if($result){
        while($row = $result->fetch_assoc()){
            $schoolID = $row['school_id'];
        }

        //Now that we have the school id we can get the school name
        $result2 = $conn->query("SELECT * FROM school WHERE school_id = '$schoolID'");
        if($result2->num_rows == 1){
            while($row = $result2->fetch_assoc()){
                $schoolName = $row['school_name'];
            }
        }else{
            $schoolName = "Too-Many Matches!!";
        }
    }

    echo $schoolName;

    $conn->close();

?>