<?php
session_start();
require_once 'db_connection.php';
date_default_timezone_set('Asia/Colombo');
$currentDate = date('Y-m-d H:i:s');

$searchQuery = $_POST['searchQuery'];

// Perform the database query based on the search query
$stmt = $conn->prepare('SELECT * FROM mobileproducts WHERE proname LIKE :searchQuery ORDER BY prid');
$stmt->bindValue(':searchQuery', '%' . $searchQuery . '%');
$stmt->execute();

// Build the dropdown options based on the query results
$options = '<option selected>Select/Search Product</option>';
if ($stmt->rowCount() > 0) {
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $options .= '<option value="' . $row['prid'] . '">' . $row['proname'] . ' | Stock Balance: ' . $row['qty'] . '</option>';
    }
} else {
    $options .= '<option disabled>No matching products found</option>';
}

// Return the options as the response to the AJAX request
echo $options;
?>
