<?php
header('Content-Type: application/json');

// Assuming you have a database connection
include 'shikanisha.kts.php';

// Adjusted SQL query with proper column names and aliases
$sql = "
  SELECT 
    `beverage_id` AS id, 
    `beverage_name` AS name, 
    `quantity` AS quantity_available, 
    'Beverage' AS category 
  FROM `beverages`
  UNION ALL
  SELECT 
    `id` AS id, 
    `name` AS name, 
    `quantity` AS quantity_available, 
    'Ingredient' AS category 
  FROM `ingredients`
  UNION ALL
  SELECT 
    `tot_id` AS id, 
    `name` AS name, 
    `quantity` AS quantity_available, 
    'Tots' AS category 
  FROM `tots`
";

$result = mysqli_query($conn, $sql);
$data = [];

while ($row = mysqli_fetch_assoc($result)) {
  $data[] = $row;
}

echo json_encode($data);
?>
