Abin Jacob Abin Jacob - 5 months ago 27
JSON Question

Codeigniter, How to get database table data displayed in json format?

I have to display the result in json format.
my code looks like:

$query = $this->db->get();

foreach($query->result() as $row)
echo json_encode($row);

and the result looks like:


I have to get this json in [] and separated by comma (,) . that is I want the result looks like:


what all changes should I done in the code.


Retrieve the record in array and then encode it

$result = $this->db->get('country')->result_array();