我有数据库,其中包含有关电视剧的信息:
name - Californication
episode - 3
season - 6
name - Californication
episode - 4
season - 6
..
name - Californication
episode - 1
season - 7
我想得到这样的输出:
Season 6:
episode 3
episode 4
Season 7:
episode 1
episode 2
....
尝试过几种方式,甚至成功了,但我相信最好在这里问一个轻便的方法。 感谢
答案 0 :(得分:0)
我会用PHP完成所有分组。
$seasons = array();
while ($row = $result->fetch()) {
if (!isset($seasons[$row->season]) {
$seasons[$row->season] = array();
}
$seasons[$row->season][] = $row->episode;
}
结果是多维数组,每个季节都作为一个关键,并以其剧集数组作为值。