<?php
include "../db.php";

if (isset($_POST['uref_code'])) {
    $uref_code = mysqli_real_escape_string($con, $_POST['uref_code']);

    $sql = "SELECT uname, ucontact FROM users WHERE utype = 'Teacher' AND admin_ref = '$uref_code' ORDER BY uid DESC";
    $result = mysqli_query($con, $sql);

    if (mysqli_num_rows($result) > 0) {
        echo "<ol>";
        while ($row = mysqli_fetch_assoc($result)) {
            echo "<li>" . htmlspecialchars($row['uname']) . "<br> <i class='fa fa-phone' style='font-size: 12px;' aria-hidden='true'></i> " . htmlspecialchars($row['ucontact']) . "</li>";
        }
        echo "</ol>";
    } else {
        echo "No teachers found.";
    }

    mysqli_close($con);
}
?>