<?php
// include('includes/config.php');
// $q = $_GET['q'] ?? '';
// $sql = "SELECT StudentID, FullName FROM tblstudents WHERE StudentID LIKE :query OR FullName LIKE :query LIMIT 10";
// $stmt = $dbh->prepare($sql);
// $search = "%$q%";
// $stmt->bindParam(':query', $search, PDO::PARAM_STR);
// $stmt->execute();
// $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
// echo json_encode($results);

include('includes/config.php');

$q = $_GET['q'] ?? '';

// Fetch only active students
$sql = "SELECT StudentID, FullName FROM tblstudents WHERE Status = 1 AND (StudentID LIKE :q OR FullName LIKE :q) LIMIT 20";
$query = $dbh->prepare($sql);
$searchTerm = "%$q%";
$query->bindParam(':q', $searchTerm, PDO::PARAM_STR);
$query->execute();

$results = $query->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($results);
