douliaodan2738 2012-03-23 19:23
浏览 30

分组SQL查询

I am working on a movie archive management system, I need to group the query results in the cases with more than one result

For example, when a user searches a director name(e.g. Steven), There are movies of Steven A, Steven B and Steven C,(multiple) what I want to do is display all movies of Steven A under his name, Steven B under his name etc.

How can I do this with php and mysql

Thanks

  • 写回答

2条回答 默认 最新

  • dongshanxun6479 2012-03-23 19:25
    关注

    Use ORDER BY director_name. This will cause rows with the same name to be listed together.

    You can also use some code in PHP to detect when the director name changes add a header if you wish to make the change from one director to the next more obvious.

    while (/* read row */)
    {
        $director_name = ...; // Implement this.
    
        if ($previous_director_name !== $director_name) {
            echo ...; // Output director's name.
            $previous_director_name = $director_name;
        }
    
        echo ...; // Output row.
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败