the effect to be obtained is
[{"name": "aaa", "id": "1", "sex", "man"}, {"name": "bbb", "id": "2", "sex", "woman"}, {}.]
now the display is
{"name": "aaa", "id": "1", "sex", "man"} {"name": "bbb", "id": "2", "sex", "woman"} {}.
my code:
<?php
defined("BASEPATH") OR exit("No direct script access allowed");
class Demo extends CI_Controller {
public function index() {
$this->load->database();
$query = $this->db->query("SELECT name, id, sex FROM user");
foreach ($query->result() as $row){
echo json_encode($row);
}
}
}
how should I modify it?