<?php
include 'connect.php';
// $q=$_POST['q'];
if(!isset($_GET['q'])){
echo"No Id";
}
else{
$q=$_GET['q'];
$sql = "SELECT a_items.*, 
               a_categories.CategoryName AS category_name
               FROM a_items
        LEFT JOIN a_categories ON a_items.CategoryID_FK = a_categories.CategoryID
        WHERE a_items.ItemName LIKE '%$q%'
        OR a_categories.CategoryName LIKE '%$q%'";

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

if ($result) {
    if (mysqli_num_rows($result) > 0) {
        $temparray=array();
        while ($row = mysqli_fetch_assoc($result)) {
           $temparray[]=[
             'item_id'=>$row['ItemID'],
            'description'=>$row['ItemName'],
            'image'=>$row['ItemImage'],
            'show_status'=>$row['ItemShow_status'],
            'out_status'=>$row['ItemOutOfStock_status'],
            'promotion'=>$row['Promotion'],
            'category_id'=>$row['CategoryID_FK'],
               ];
        }
         echo json_encode($temparray);
         mysqli_free_result($result);
        
    } else {
         $arr=array();
         $array[]=[
             'status'=>'notfound'
             ];
        echo json_encode($array);
    }
} 

mysqli_close($con);

}
?>