|
输入网站,
我要获得的效果是 [{"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);
}
}
}
因为新手,看了一大圈,不是很明白怎么来实现,卡了好几天。
求指点。
|
|