title: How to get two mysql querie results in one JSON array?
body: <p>in my current project I have to create a JSON array, in which for each day a status with a colour is displayed in a calendar (FullCalendar) and additionally a button with a link is to be displayed for all days where an event is planned.</p>
  <p>For this I have two SELECT's which both work on their own. I have already tried some things how to put the results of both SELECT's into one JSON array, but I keep getting the error 'Undefinded Variable'.</p>
  <p>How do I have to pack the results of the two SELEC T's put together that all results are displayed correctly?</p>
  <pre><code>header('Content-Type: application/json');
  
  include &quot;../../../includes/db.php&quot;;
  
  if(isset($_GET['team_id'])) {
     $team_id = $_GET['team_id'];
  }
  
  $stmt = $connection-&gt;prepare(&quot;SELECT date FROM date&quot;);
  $stmt-&gt;execute();
  $result = $stmt-&gt;get_result();
  while($row = $result-&gt;fetch_assoc()) {
  
     $date = $row['date'];
  
     $team_planner_user_status_present = 1;
     $team_planner_user_status_absent = 2;
     $team_planner_user_status_reservation = 3;
     $stmt1 = $connection-&gt;prepare(&quot;SELECT 
                                     (
                                        SELECT COUNT(*)
                                        FROM team_planner_user 
                                        INNER JOIN user ON team_planner_user.user_id = user.user_id 
                                        WHERE user.team_id = ?
                                        AND team_planner_user.date = ?
                                        AND team_planner_user.team_planner_user_status = ?
                                     ) AS present,
                                     (
                                        SELECT COUNT(*)
                                        FROM team_planner_user 
                                        INNER JOIN user ON team_planner_user.user_id = user.user_id 
                                        WHERE user.team_id = ?
                                        AND team_planner_user.date = ?
                                        AND team_planner_user.team_planner_user_status = ?
                                     ) AS absent,
                                     (
                                        SELECT COUNT(*)
                                        FROM team_planner_user 
                                        INNER JOIN user ON team_planner_user.user_id = user.user_id 
                                        WHERE user.team_id = ?
                                        AND team_planner_user.date = ?
                                        AND team_planner_user.team_planner_user_status = ?
                                     ) AS reservation
                                  &quot;);
  $stmt1-&gt;bind_param(&quot;sssssssss&quot;, $team_id, $date, $team_planner_user_status_present, 
                                  $team_id, $date, $team_planner_user_status_absent, 
                                  $team_id, $date, $team_planner_user_status_reservation);
  $stmt1-&gt;execute();
  $result1 = $stmt1-&gt;get_result();
  while($row1 = $result1-&gt;fetch_array()) {
              
      $present = $row1['present'];
      $absent = $row1['absent'];
      $reservation = $row1['reservation'];
  
      if($present &gt;= 5) {
          $color = '#a1ff9e';
      } else if($present + $reservation &gt;= 5) {
          $color = '#fcff9e';
      } else {
          $color = '#ff9e9e';
      }
  }
  
  $stmt1-&gt;close();
  
  $stmt2 =$connection-&gt;prepare(&quot;SELECT * FROM game_planned INNER JOIN game_role ON game_planned.match_role_id = game_role.match_role_id WHERE team_id = ? AND game_planned_date = ?&quot;);
  $stmt2-&gt;bind_param(&quot;ss&quot;, $team_id, $date);
  $stmt2-&gt;execute();
  $result2 = $stmt2-&gt;get_result();
  while($row2 = $result2-&gt;fetch_array()) {
      $match_role_name = $row2['match_role_name'];
      $game_planned_id = $row2['game_planned_id'];
  }
  
  $data[] = array(
      'start' =&gt; $date,
      'display' =&gt; 'background',
      'color' =&gt; $color,
  );
  
  if($result-&gt;num_rows === 0) {
      echo &quot;&quot;;
  } else {
      $data[] = array(
          'title' =&gt; $match_role_name,
          'url' =&gt; 'http://localhost/r6team-redesign/team/team.php?team=details-match-plan&amp;match_planned_id='.$game_planned_id,
          'start' =&gt; $date,
      );
  }
  }
  
  $stmt-&gt;close();
  
  echo json_encode($data);
  </code></pre>