Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $host = "localhost";
- $username = "root";
- $password = "rootacc";
- $database = "inrestaurant";
- $restDat = "restaurant_data";
- $userDat = "user_data";
- $staffDat = "staff_data";
- function GET_DATA($tableName, $isAdmin, $data = null)
- {
- global $dbConn;
- if(!$dbConn)
- {
- //Invalid Connection
- echo "Unable to establish a connection to host\n\n".mysqli_connect_errno().PHPEOL."<br>";
- }
- else
- {
- //Valid Connection
- if($tableName == "restaurant_data" && $data == null)
- GET_RESTDAT($dbConn, $isAdmin);
- else if ($tableName == "staff_data"&& $data == null)
- GET_STAFFDAT($dbConn);
- else if ($isAdmin && ($tableName == "restaurant_data" || $tableName == "staff_data") && $data != null)
- GET_DAT_SINGLE($dbConn, $tableName, $data);
- }
- }
- function GET_DAT_SINGLE($dbConn, $tableName, $data)
- {
- if($tableName == "staff_data")
- {
- $columnNames = "staffID, staffName, staffContactNo, staffEmail";
- $condition = "staffID = '".$data;
- }
- else if($tableName == "restaurant_data")
- {
- $columnNames = "restaurantID, restaurantName, restaurantType, restaurantLot, restaurantOwn, restaurantContactNo, restaurantEmail";
- $condition = "restaurantID = '".$data;
- }
- $query = "SELECT ".$columnNames." FROM ".$tableName." WHERE ".$condition."'";
- $result = mysqli_query($dbConn, $query);
- if($result)
- {
- if(mysqli_num_rows($result) != 0 )
- {
- $row = mysqli_fetch_assoc($result);
- echo json_encode($row);
- }
- else
- {
- echo "Failed to retrieve a valid data";
- }
- }
- else
- {
- echo "Invalid Input";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement