Files
4WDCSA.co.za/src/api/fetch_bar_tabs.php
twotalesanimation be2b757f4e Code restructure push
2025-12-04 15:09:44 +02:00

37 lines
909 B
PHP

<?php
$rootPath = dirname(dirname(__DIR__));
require_once($rootPath . "/src/config/session.php");
require_once($rootPath . "/src/config/connection.php");
require_once($rootPath . "/src/config/functions.php");
// Prepare the SQL query to fetch bar tabs along with user details, including user_id
$sql = "
SELECT bt.tab_id, u.user_id, u.first_name, u.last_name, u.profile_pic
FROM bar_tabs bt
JOIN users u ON bt.user_id = u.user_id
";
// Execute the query
$result = mysqli_query($conn, $sql);
// Check if there are results
if (mysqli_num_rows($result) > 0) {
// Create an array to hold the data
$barTabs = [];
// Fetch each row
while ($row = mysqli_fetch_assoc($result)) {
$barTabs[] = $row;
}
// Return the data as JSON
echo json_encode($barTabs);
} else {
echo json_encode([]);
}
// Close the database connection
mysqli_close($conn);
?>