Advertisement
Guest User

Untitled

a guest
Nov 1st, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1.     $host = "localhost";
  2.     $username = "root";
  3.     $password = "rootacc";
  4.    
  5.     $database = "inrestaurant";
  6.  
  7.     $restDat = "restaurant_data";
  8.     $userDat = "user_data";
  9.     $staffDat = "staff_data";
  10.  
  11.     function GET_DATA($tableName, $isAdmin, $data = null)
  12.     {
  13.         global $dbConn;
  14.  
  15.         if(!$dbConn)
  16.         {
  17.             //Invalid Connection
  18.             echo "Unable to establish a connection to host\n\n".mysqli_connect_errno().PHPEOL."<br>";
  19.         }
  20.         else
  21.         {
  22.             //Valid Connection
  23.             if($tableName == "restaurant_data" && $data == null)
  24.                 GET_RESTDAT($dbConn, $isAdmin);
  25.             else if ($tableName == "staff_data"&& $data == null)
  26.                 GET_STAFFDAT($dbConn);
  27.             else if ($isAdmin && ($tableName == "restaurant_data" || $tableName == "staff_data") && $data != null)
  28.                 GET_DAT_SINGLE($dbConn, $tableName, $data);
  29.         }
  30.     }
  31.  
  32.     function GET_DAT_SINGLE($dbConn, $tableName, $data)
  33.     {
  34.         if($tableName == "staff_data")
  35.         {
  36.             $columnNames = "staffID, staffName, staffContactNo, staffEmail";
  37.             $condition = "staffID = '".$data;
  38.         }
  39.         else if($tableName == "restaurant_data")
  40.         {
  41.             $columnNames = "restaurantID, restaurantName, restaurantType, restaurantLot, restaurantOwn, restaurantContactNo, restaurantEmail";
  42.             $condition = "restaurantID = '".$data;
  43.         }
  44.  
  45.         $query = "SELECT ".$columnNames." FROM ".$tableName." WHERE ".$condition."'";
  46.         $result = mysqli_query($dbConn, $query);
  47.  
  48.         if($result)
  49.         {
  50.             if(mysqli_num_rows($result) != 0 )
  51.             {
  52.                 $row = mysqli_fetch_assoc($result);
  53.                 echo json_encode($row);
  54.             }
  55.             else
  56.             {
  57.                 echo "Failed to retrieve a valid data";
  58.             }
  59.         }
  60.         else
  61.         {
  62.             echo "Invalid Input";
  63.         }
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement