Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在codeigniter中设计包含多个对象的json字符串?_Php_Json_Codeigniter - Fatal编程技术网

Php 如何在codeigniter中设计包含多个对象的json字符串?

Php 如何在codeigniter中设计包含多个对象的json字符串?,php,json,codeigniter,Php,Json,Codeigniter,我有两张桌子,桌子上的照片有以下数据 照片ID照片名称 1.1巴布亚新几内亚 2.2巴布亚新几内亚 3 x.png 4西巴布亚新几内亚 。。。还有更多 和具有以下数据库的表photocomment pcid感光内容 这里有一些评论 。。。还有更多 我想得到这样的json字符串 { "status":"1", "fbmsg":"success", "photolist":[ { "photoid":"1", "photoname":"

我有两张桌子,桌子上的照片有以下数据

照片ID照片名称 1.1巴布亚新几内亚

2.2巴布亚新几内亚

3 x.png

4西巴布亚新几内亚

。。。还有更多 和具有以下数据库的表photocomment

pcid感光内容

这里有一些评论

。。。还有更多

我想得到这样的json字符串

{
    "status":"1",
    "fbmsg":"success",
    "photolist":[
    {
        "photoid":"1",
        "photoname":"1.png",
        "commentlist":[
         {
            "pcid":"1",
            "commentcontent":"here some comments"
          },
          ... more results  
         ]
       },
        .... more results
     ]
    }
在CI控制器中,我写道

  $this->load->model('bbs_model');
  $query = $this->bbs_model->listphotos();
  if ($query) {
    echo json_encode(array(
      'status' => 1,
      'fbmsg' => 'success',
      'typelist' => $query
    ));
    exit();
  }
在CI模型中,我写道

  function listphotos()
  {
    $query = $this->db->query("select * from photos order by photoid asc");
    return $query->result_array();
   }

如何修改控制器和模型以创建上面的json字符串?谢谢。

根据需要生成数组并对其进行json_编码。@ShaifulIslam谢谢,我如何才能在model and controller中获得commentlist?