<?php
include("configa.php");

$ref = "147";

if (isset($_GET['q'])) {
    $q = mysqli_real_escape_string($conn, $_GET['q']);

    $sql = "SELECT id, product_name, product_nameEn, category_picture 
            FROM goods_category 
            WHERE product_name LIKE '%$q%' 
               OR product_nameEn LIKE '%$q%' 
            LIMIT 10";

    $result = mysqli_query($conn, $sql);

    if (mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_object($result)) {
            echo '<div class="imgFromSearchBox">';

            // category_picture থাকলে ছবি দেখাও
            if (!empty($row->category_picture)) {
                echo '
                <a style="width: 100%;" class="anchorSearchResults" href="product_individual.php?id=' . $row->id . '&ref=' . $ref . '" data-category="Food"> <div style="width: 100%; display: flex; align-items: center;">
                <img class="category_imageFromSearch" src="category/' . htmlspecialchars($row->category_picture) . '">';
            }      
            echo htmlspecialchars($row->product_name) . ' / ' . htmlspecialchars($row->product_nameEn);
            echo '</div></a>';
            echo '</div>';
        }
        
    } else {
        // echo "No matches found.";
    }
}
?>


