handling json MySQL result objects [solved]

handling json MySQL result objects [solved]

coreywcoreyw Posts: 6Questions: 1Answers: 0
edited March 2012 in General
Hi All,

I've got a $result of a MySQL query in a php script. I json encode it to send it back to DataTables to see what would happen.

$result = array('aaData' => $result );
echo json_encode($result);

The json looks like this.

{"sEcho":1,"iTotalRecords":1,"iTotalDisplayRecords":1,"aaData":[[{"Id":"0","ContactTypeId":"0","Prefix":"Mr.","FirstName":"Peter","LastName":"Bliss","Suffix":"M.Sc.","Title":"Dr.","Position":"Chairperson","AddressId":"0","WorkDescription":"Head guru","BirthDate":"0000-00-00 00:00:00","Gender":"M"}]]}

DataTables spews an error 'Requested unknown parameter '0' from the data source for row 0'. I'm assuming this is because the payload is an array of objects, and not a simple associative array.

json'ing the MYSql $result is very clean code-wise, but isn't accepted. Can anyone can me any snippets of wisdom before I go and pull out all the columns and build the json manually?

Thanks!
Corey.

Replies

  • coreywcoreyw Posts: 6Questions: 1Answers: 0
    Ah - I upgraded to the latest DataTables and found mDataProp in aoColumns. That did the trick!
This discussion has been closed.