title: Retrieve all values in my loop and format it to json
body: <p>I'm trying to build a page which queries my database and then formats output so another <code>webservice/page</code> can access the data. </p>
  
  <p>Ideally I wanted to explore having the data in JSON format, but that is not working. The other problem I have which is more major than the JSON not working is, if I have 3 records in <code>$reportsResult</code>, only the last one is displayed. </p>
  
  <p>Anyone with some help please. Oh do I also need to <code>print_r</code> for the external webpage to retrieve the data or is there a better way?    </p>
  
  <pre><code>class Pupil {
      public $FirstName = "";
      public $LastName  = "";
  }
  
  foreach($reportsResult-&gt;getRecords() as $reportRecord) {
      $Pupil = new Pupil();
      $Pupil-&gt;FirstName = $reportRecord-&gt;getField('FName');
      $Pupil-&gt;LastName = $reportRecord-&gt;getField('SName');
  }
  json_encode($Pupil);
  </code></pre>
  
  <p>OK managed to figure out how how to get all records from the loop, but its still not displaying in json format when I do a print_r - am I missing something?</p>
  
  <pre><code>$AllPupils = array();
  
  foreach($reportsResult-&gt;getRecords() as $reportRecord)
  {
  
  $Pupil = new Pupil();
  $Pupil-&gt;FamID = $reportRecord-&gt;getField('FName');
  $Pupil-&gt;ChildName = $reportRecord-&gt;getField('SName');
  
  array_push($AllPupils, $Pupil);
  }
  
  json_encode($AllPupils);
  </code></pre>