<?php
include 'admin/connection.php';

if (isset($_GET['q'])) {
    $q = $conn->real_escape_string($_GET['q']);

    // Fetch matching products
    $res = $conn->query("SELECT id, title FROM products WHERE status=1 AND title LIKE '%$q%' LIMIT 10");

    if ($res->num_rows > 0) {
        while ($row = $res->fetch_assoc()) {
            echo '<a href="product-detail.php?id=' . $row['id'] . '">' . htmlspecialchars($row['title']) . '</a>';
        }
    } else {
        echo '<a href="#">No products found</a>';
    }
}

