继承人的功能: http://pastebin.com/tQLjzzbH
我想让它归还:
{"years":[
{
"yName":"2011",
"yAlbums:[
{
auID:"1234",
aID:"456",
etc..
},
{
auID:"12345",
aID:"4567",
etc..
}
},
{
"yName":"2010",
"yAlbums:[
{
auID:"2234",
aID:"556",
etc..
}
}
]}
但它只返回这个:
{"years":[
{"yName":"2011"},
{"yName":"2010"}]}
多年来一直试图解决这个问题,现在我完全迷失了。一些帮助将不胜感激。
感谢。
答案 0 :(得分:1)
你已经通过
阅读了你的结果while($data2 = mysql_fetch_assoc($result))
{
$yearsArrayRaw[] = $data2['album_year'];
}
在内部mysql_data_seek($result,0)
之前添加while
到第36行。另外,我建议使用类似
$year_albums= array();
while ($data = mysql_fetch_assoc($result)){
if (empty($years[$data['album_year']])){
$year_albums[$data['album_year'] = array(
'yName'=>$data['album_year'],
'yAlbums'=>array()
);
}
//...album creation logic here...//
$year_albums[$data['album_year']['yAlbums'][] = $album;
}
//Converting arrays into objects
$years = array();
foreach ($year_albums as $year){
$years[] = (object)$year;
}
json_encode($years);