doude1917 2015-07-10 14:09
浏览 39

如何按不同变量分组列表?

I'm trying to make a list where the format goes as follows:

CLUB

  • name
  • name
  • name

CLUB 2

  • name
  • name

So far, I've managed to autogenerate tables but for each name it displays the name of the club above, even if it's the same club as another one above it. I've tried to do it through mysqli, I don't know if it would be better through PHP. Here's my query so far:

$sql = "SELECT DISTINCT soc.nombre, soc.apellido, club.nombreClub FROM socios as soc
INNER JOIN club4h as club
ON soc.nombreClub = club.nombreClub";

$result =NULL;
foreach($conn->query($sql) as $row){
    $club[] = $row["nombreClub"];
    $nombreSoc[] = $row["nombre"];
    $apellidoSoc[] = $row["apellido"];
}

And here's how it's looking with that query:

enter image description here

  • 写回答

1条回答 默认 最新

  • dsp15140275697 2015-07-10 14:26
    关注

    You can just use order by statement in your SQL query

    $sql = "SELECT DISTINCT soc.nombre, soc.apellido, club.nombreClub FROM 
    socios as soc
    INNER JOIN club4h as club
    ON soc.nombreClub = club.nombreClub
    ORDER NY club.nombreClub DESC, soc.nombre DESC";
    

    So this way you will get your data sorted out of the database and all you need to do is display it.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程