title: Retrieving a database record set into an array in php
body: <p>I want to retrieve a set of records from a MySQL table as an array.</p>
  
  <p>So far I was able to retrieve each row as an associative array. But I want all the rows in one array because I have to access that complete object in jQuery to display them.</p>
  
  <p>This is what I have done so far.This is my .php script to retrieve data</p>
  
  <pre><code>//select query    
  $result = mysql_query("SELECT * FROM student",$con) or die (mysql_error());
  
  $numRows = mysql_num_rows($result); //to iterate the for loop
  
  //passing as an associative array
  
  for ($count = 0; $count &lt; $numRows; $count++){
      $row = mysql_fetch_array($result, MYSQL_ASSOC);
      echo json_encode($row);     
  }
  </code></pre>
  
  <p>This is what I currently get</p>
  
  <pre><code>{"StuId":"1","fName":"Saman","lName":"Kumara","age":"14","grade":"A"}
  {"StuId":"2","fName":"Marry","lName":"Vass","age":"12","grade":"B"}
  {"StuId":"3","fName":"Navjoth","lName":"Bogal","age":"32","grade":"A"}
  {"StuId":"4","fName":"Jassu","lName":"Singh","age":"22","grade":"E"} 
  </code></pre>
  
  <p>But I want this result set as follows.       </p>
  
  <pre><code>[
      {"TEST1":45,"TEST2":23,"TEST3":"DATA1"},
      {"TEST1":46,"TEST2":24,"TEST3":"DATA2"},
      {"TEST1":47,"TEST2":25,"TEST3":"DATA3"}
  ]
  </code></pre>
  
  <p>I seek help in doing this. Thanks in advance.</p>