要获得的效果是:[{"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);
}
}
}
我该如何修改?
2 回答
UYOU
TA贡献1878条经验 获得超4个赞
public function index() {
$this->load->database();
$query = $this->db->query('SELECT name, id, sex FROM user');
echo json_encode($query);
}
这样不久可以了吗
- 2 回答
- 0 关注
- 612 浏览
添加回答
举报
0/150
提交
取消