javascript - jQuery dataTables with Codeigniter and sAjaxSource -
i using datatables codeigniter , have problem. getting message:
array_push() expects parameter 1 array, null given
and result {"aadata":null}
i want this: { "aadata": [ ["test","test","test"] ] }
code:
$result = $this->lol_model->get(); //result = array ( [0] => stdclass object ( [test] => 12345 [test2] => 1842 07 03 [test3] => lol ) ) $aadata = array(); foreach($result $row) { array_push($json["aadata"],array( $row->test, $row->test2, $row->test3 )); } echo json_encode($json);
you cannot define key '["aadata"]' when using array_push. however, can use:
$json["aadata"]=array( $row->test, $row->test2, $row->test3 );
see post also: array_push() key value pair
Comments
Post a Comment