使用PHP将MySQL查询转换为JSON对象

I am new to programming and have a question about converting a MYSQL query with a Join into a JSON object using PHP. When running the statement through phpMyAdmin I get results. However, when attempting the convert it into a JSON object I am getting a blank screen. Any help is greatly appreciated! Here is my code:

    $myquery = "SELECT track_ticseverity.date, track_ticseverity.ticnum, track_ticseverity.user_id, track_fatigue.date, track_fatigue.fatiguenum, track_fatigue.user_id 
    FROM track_ticseverity
          INNER JOIN track_fatigue
          ON track_ticseverity.date=track_fatigue.date
          WHERE track_ticseverity.user_id=1
          AND track_fatigue.user_id=1;"

    $query = mysqli_query($conn, $myquery);

   if ( ! $query ) {
       echo mysqli_error();
       die;
   }

   $data = array();

   for ($x = 0; $x < mysqli_num_rows($query); $x++) {
       $data[] = mysqli_fetch_assoc($query);
   }

   echo json_encode($data);     

   mysqli_close($server);

Did you connect to your database? (mysqli_connect)

It's not in your code example, but maybe you did anyway and didn't copy it.

If you did, to which variable did you assign the connection? Once you're using $conn in mysqli_query and once youre using $server in mysqli_close.

Maybe this is helping already even I think PHP should show errors in this case?

Another Tipp

You can easily write the following:

while($datarow = mysqli_fetch_assoc($query))  {
    $data[] = $datarow;
}

Like this, you can save the for-loop.

I just figured it out. I ended my Query with ;" instead of "; Thanks for your replies! Sorry I did not catch that before posting!