I'm using a jquery plugin called DataTables, and it requires me to return a json string in order to render the table.
Currently, the outputted json looks like this (see the aaData array):
{"sEcho":0,"aaData":[[{"ID":"1","idPatient":"122342","idFacility":"3","idTreatment":"3"}]]}
I'm wondering if the { } braces should actually be in the aaData array. In fact, I think the braces are actually what's causing the JSON parse error.
The actual code that generates this is listed below. (core->dbh is a PDO handle)
<?php
require_once('core/Core.php');
$core = Core::get_instance();
$sql = 'SELECT ID, idPatient, idFacility, idTreatment
FROM Pathology WHERE idPatient = 122342';
$stmt = $core->dbh->prepare($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
// bind parameters
$stmt->execute();
// prepare output for DataTables
$data = array("sEcho" =>intval($_GET['sEcho']),
"aaData" =>array()
);
while($result = $stmt->fetchAll()) {
$data['aaData'][] = $result;
}
echo json_encode($data);
?>
Could someone please tell me how can I remove the curly braces, or if the JSON is improperly formatted in another way that could be causing the parse error?
Thanks