<?php
include 'includes/db.php';

$suchbegriff = trim($_GET['s'] ?? '');

if ($suchbegriff === '') {
    echo json_encode([]);
    exit;
}

$stmt = $conn->prepare("SELECT id, artikelnummer, artikelname FROM lager_bestand WHERE artikelnummer LIKE ? OR artikelname LIKE ? ORDER BY artikelname ASC");
$like = '%' . $suchbegriff . '%';
$stmt->bind_param("ss", $like, $like);
$stmt->execute();
$result = $stmt->get_result();

$treffer = [];
while ($row = $result->fetch_assoc()) {
    $treffer[] = $row;
}

echo json_encode($treffer);
exit;
?>
