<?php
include '../config/db.php';

$searchTerm = $_GET['q'];
$query = "SELECT drug_name FROM drugs WHERE drug_name LIKE :searchTerm LIMIT 10";
$stmt = $pdo->prepare($query);
$stmt->execute(['searchTerm' => '%' . $searchTerm . '%']);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach ($results as $result) {
    echo '<a href="#" class="list-group-item list-group-item-action" onclick="selectSuggestion(\'' . htmlspecialchars($result['drug_name']) . '\')">' . htmlspecialchars($result['drug_name']) . '</a>';
}
