要获得的效果是:
[{"name":"aaa","id":"1","sex","man"},{"name":"bbb","id":"2","sex","woman"},{}...]
现在的显示是
{"name":"aaa","id":"1","sex","man"}{"name":"bbb","id":"2","sex","woman"}{}...
我的代码:
<?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);
}
}
}
我该如何修改?
UYOU