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(); ?>