title: Codeigniter, How to get database table data displayed in json format?
body: <p>I have to display the result in json format.
  my code looks like:</p>
  
  <pre><code> $this-&gt;db-&gt;select("*");
          $this-&gt;db-&gt;from('country');  
          $query = $this-&gt;db-&gt;get();
  
          foreach($query-&gt;result() as $row)
          {
              echo json_encode($row);
          } 
  </code></pre>
  
  <p>and the result looks like:</p>
  
  <pre><code>{"id":"1","country_name":"Australia","country_code":"61"}{"id":"2","country_name":"Bangladesh","country_code":"880"}{"id":"3","country_name":"Brazil","country_code":"55"}
  </code></pre>
  
  <p>I have to get this json in [] and separated by comma (,) . that is I want the result looks like:</p>
  
  <pre><code>[{"id":"1","country_name":"Australia","country_code":"61"},{"id":"2","country_name":"Bangladesh","country_code":"880"},{"id":"3","country_name":"Brazil","country_code":"55"}] 
  </code></pre>
  
  <p>what all changes should I done in the code.</p>