title: AngularJS FullCalendar get events by ID
body: <p>Im trying to get calendar events from mysql db using fullcalendar, PHP and angularjs. </p>
  
  <p>HTTP</p>
  
  <pre><code>&lt;div ng-controller="calController" ng-show="tab4"&gt;
      &lt;div id="calendar" ui-calendar="uiConfig.calendar" ng-model="eventSources" calendar="myCalendar"&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My conroller: </p>
  
  <pre><code>.controller('calController', ['$rootScope', '$scope', '$http', 'uiCalendarConfig', function ($rootScope, $scope, $http, uiCalendarConfig) {
  
  var user = $rootScope.userID;
  
  $scope.eventSources = {
      url: 'php/events.php?agentID=' + user
  };
  
  $scope.uiConfig = {
      calendar: {
          height: 300,
          editable: false,
          allDay: false,
          header: {
              left: 'title',
              center: '',
              right: 'agendaWeek prev,next'
          }
      }
  };}]);
  </code></pre>
  
  <p>My PHP: </p>
  
  <pre><code>$sql="SELECT * FROM `Events`";$sql = $con-&gt;prepare($sql);$sql-&gt;execute();$results=$sql-&gt;fetchAll(PDO::FETCH_ASSOC); $json=json_encode($results); 
  </code></pre>
  
  <p>Im getting the results into my calendar but they all the results in the DB. Probably because the statemnt is <code>select * from events...</code></p>
  
  <p>In the controller you can see im passing the URL with my parameter "user" but this has no effect on the return of the php script. </p>
  
  <p>So my question is how do I return only a specific users events and not all the events? </p>
  
  <p>I guess my PHP file needs to be edited but I dont know what to do.. </p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>Ive also tried getting the events into an array and then binding to eventSources:</p>
  
  <pre><code>var user = $rootScope.userID;
  
  var events = [];
  
  $scope.eventSources = [events];
  
  $http.post('php/events.php', {
      'user': user
  }).success(function (data) {
  
      console.log(data);
  
      angular.forEach(data, function (value) {
  
          events.push({
              start: value.start,
              end: value.end
          });
      });
  
      console.log("events", events);
      console.log("sources", $scope.eventSources);
  
  });
  </code></pre>
  
  <p>This works well to get events using an ID but now I don't see the events in the calendar.</p>
  
  <pre><code>console.log("events", events);
  console.log("sources", $scope.eventSources);
  </code></pre>
  
  <p>The output for the above is:</p>
  
  <p><a href="https://i.stack.imgur.com/4YOhu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4YOhu.png" alt="enter image description here"></a></p>
  
  <p>Why wouldnt events be showing up in the calendar with an array? Any help would be amazing.</p>
  
  <p>Thanks</p>