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