I want to get a recordset from a MySQL table as an array.
So far, I have managed to get each row as an associative array. But I want all the rows in one array, because I have to access this full object in jQuery in order to display them.
This is what I have done so far. This is my .php script to retrieve data
//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 < $numRows; $count++){ $row = mysql_fetch_array($result, MYSQL_ASSOC); echo json_encode($row); }
This is what I'm getting right now
{"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"}
But I want this result to be set as follows.
[ {"TEST1":45,"TEST2":23,"TEST3":"DATA1"}, {"TEST1":46,"TEST2":24,"TEST3":"DATA2"}, {"TEST1":47,"TEST2":25,"TEST3":"DATA3"} ]
I am looking for help with this. Thanks in advance.