title: PHP calling another PHP page for MySQL Query (returning JSON data)
body: <p>I would like to find out how a PHP page calls another PHP page, which will return JSON data. </p>
  
  <p>I am working with PHP (UsersView.php) files to display my contents of a website. However, I have separated the MySQL Queries in another PHP (Get_Users.php) file. </p>
  
  <p>In the Get_Users.php, I will have a MySQL statement to query the database for data. It will then encode in JSON and be echo-ed out. </p>
  
  <p>In the UsersView.php, I will call the Get_Users.php in order to retrieve the Users JSON data. The data will then be used to populate a "Users Table".</p>
  
  <p>The thing is, I do not know how to call the "Get_Users.php" from the "UsersView.php" in order to get the data. </p>
  
  <p><strong>Part of UserView.php</strong></p>
  
  <pre><code>$url =  "get_user.php?id=" . $id;
  $json = file_get_contents($url);
  $result = json_decode($json, true);
  </code></pre>
  
  <p>I am trying to call the file which is in the same directory, but this does not seem to work. </p>
  
  <p><strong>Whole of Get_Users.php</strong></p>
  
  <pre><code>&lt;?php
  $connection = mysqli_connect("localhost", "root", "", "bluesky");
  
  // Test if connection succeeded
  if(mysqli_connect_errno()) {
      die("Database connection failed: " . mysqli_connect_error() . " (" . mysqli_connect_errno() . ") " .
          "&lt;br&gt;Please retry your last action. Please retry your last action. " .
          "&lt;br&gt;If problem persist, please follow strictly to the instruction manual and restart the system.");
  }
  
  $valid = true;
  
  if (!isset($_GET['id'])) {
      $valid = false;
      $arr=array('success'=&gt;0,'message'=&gt;"No User ID!");
      echo json_encode($arr);
  }
  
  $id = $_GET['id'];
  
  if($valid == true){
      $query = "SELECT * FROM user WHERE id = '$id'";
      $result = mysqli_query($connection, $query);
      if(mysqli_num_rows($result) == 1){
          $row = mysqli_fetch_assoc($result);
          $arr=array('success'=&gt;1,'type'=&gt;$row['type'],'user_id'=&gt;$row['id'],'email'=&gt;$row['email'],'name'=&gt;$row['name'],'phone'=&gt;$row['phone'],'notification'=&gt;$row['notification']);
          echo json_encode($arr);
      }else{
          $arr=array('success'=&gt;0,'message'=&gt;"Invalid User ID!");
          echo json_encode($arr);
      }
  }
  
  mysqli_close($connection);
  ?&gt;
  </code></pre>