<?php
require 'db.php'; // your PDO connection

$search = $_GET['q'] ?? '';

$stmt = $pdo->prepare(
    "SELECT DISTINCT item
     FROM transactions
     WHERE item IS NOT NULL AND item != ''
       AND item LIKE ?
     ORDER BY item
     LIMIT 20"
);

$stmt->execute(["%$search%"]);
$items = $stmt->fetchAll(PDO::FETCH_COLUMN);

echo json_encode($items);