Code restructure push
This commit is contained in:
30
src/api/fetch_drinks.php
Normal file
30
src/api/fetch_drinks.php
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
|
||||
<?php
|
||||
$rootPath = dirname(dirname(__DIR__));
|
||||
require_once($rootPath . "/src/config/connection.php");
|
||||
|
||||
if (isset($_GET['tab_id'])) {
|
||||
$tab_id = (int) $_GET['tab_id']; // Convert to integer
|
||||
|
||||
if ($tab_id <= 0) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Invalid tab ID.']);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Fetch drinks available for this tab
|
||||
$stmt = $conn->prepare("SELECT * FROM bar_items");
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
$drinks = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$drinks[] = $row;
|
||||
}
|
||||
|
||||
echo json_encode($drinks);
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Tab ID is required.']);
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user