php ci框架 查询mysql 返回json数组

要获得的效果是:[{"name":"aaa","id":"1","sex","man"},{"name":"bbb","id":"2","sex","woman"},{}...]
现在的显示是{"name":"aaa","id":"1","sex","man"}{"name":"bbb","id":"2","sex","woman"}{}...
我的代码:
defined('BASEPATH')ORexit('Nodirectscriptaccessallowed');
classDemoextendsCI_Controller{
publicfunctionindex(){
$this->load->database();
$query=$this->db->query('SELECTname,id,sexFROMuser');
foreach($query->result()as$row){
echojson_encode($row);
}
}
}
我该如何修改?
肥皂起泡泡
浏览 798回答 2
2回答

慕尼黑8549860

已解决

桃花长相依

publicfunctionindex(){$this->load->database();$query=$this->db->query('SELECTname,id,sexFROMuser');echojson_encode($query);}这样不久可以了吗
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript