为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
慕仙森 2019-03-16 17:47:19
要获得的效果是:[{"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);
}

这样不久可以了吗

查看完整回答
反对 回复 2019-03-18
  • 2 回答
  • 0 关注
  • 612 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信