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

$searchTerm = isset($_GET['q']) ? $_GET['q'] : '';

$sql = "SELECT main_id, jobcard_no 
        FROM jobcard_main 
        WHERE jobcard_no LIKE ? 
        ORDER BY jobcard_no ASC
        LIMIT 50";

        
$stmt = $conn->prepare($sql);
$likeTerm = "%$searchTerm%";
$stmt->bind_param("s", $likeTerm);
$stmt->execute();
$result = $stmt->get_result();

$data = [];
while ($row = $result->fetch_assoc()) {
    $data[] = ['id' => $row['main_id'], 'text' => $row['jobcard_no']];
}

echo json_encode(['results' => $data]);
?>
