Code restructure push
This commit is contained in:
36
src/api/fetch_bar_tabs.php
Normal file
36
src/api/fetch_bar_tabs.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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);
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user