0

我有数据库,其中包含有关电视连续剧的信息,如下所示:

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
....

尝试了好几种方法,甚至都成功了,不过我相信还是在这里求个轻的方法比较好。谢谢

4

1 回答 1

0

我会在 PHP 中完成所有的分组。

$seasons = array();
while ($row = $result->fetch()) {
    if (!isset($seasons[$row->season]) {
        $seasons[$row->season] = array();
    }
    $seasons[$row->season][] = $row->episode;
}

结果是多维数组,每个季节作为键,其剧集数组作为值。

于 2013-03-31T02:30:35.660 回答