<?php
include 'db.php';
$term = isset($_GET['q']) ? trim($_GET['q']) : '';
if ($term == '') exit;

$sql = "SELECT id, name, stage, class 
        FROM students 
        WHERE name LIKE '%$term%' 
        ORDER BY stage, class, name LIMIT 10";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    while ($s = mysqli_fetch_assoc($result)) {
        echo "<div class='search-item' data-id='{$s['id']}'>
                👨‍🎓 {$s['name']} — {$s['stage']} / {$s['class']}
              </div>";
    }
} else {
    echo "<div class='search-item no-result'>❌ لا توجد نتائج</div>";
}
?>
