首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自SQL查询的php中的Group By标题

来自SQL查询的php中的Group By标题
EN

Stack Overflow用户
提问于 2012-10-13 03:50:38
回答 1查看 1.4K关注 0票数 0

下面是我从一个查询中得到的表:

代码语言:javascript
复制
----------+----+-----------+----------------------
45678-sm-w| 18 |T-Shirts   | Mens clothing
----------+----+-----------+----------------------
45678-sm-b|  5 |T-Shirts   | Mens clothing
----------+----+-----------+----------------------
2189-L-Wh |  4 | Socks     | Juniors Clothing
----------+----+-----------+----------------------
2189-L-Bl |  3 | Socks     | Juniors Clothing
----------+----+-----+-----+----------------------

我想把下面的内容放到报告中:

代码语言:javascript
复制
T-Shirts
----------+----+-----------+----------------------
45678-sm-w| 18 |T-Shirts   | Mens clothing
----------+----+-----------+----------------------
45678-sm-b|  5 |T-Shirts   | Mens clothing
----------+----+-----------+----------------------

Socks
 ----------+----+-----------+----------------------
2189-L-Wh |  4 | Socks     | Juniors Clothing
----------+----+-----------+----------------------
2189-L-Bl |  3 | Socks     | Juniors Clothing
----------+----+-----+-----+----------------------

我知道它是通过一个循环来完成的,但我无法弄清楚它。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-13 04:10:53

尝试按项目类型对查询进行排序,并在当前标题更改时强制显示标题。

代码语言:javascript
复制
$res = mysql_query("select * from clothing order by item_type, item_size");

$item_type=null;
while ($row = mysql_fetch_assoc($res)) {
    if ($item_type != $row['item_type']) {
        $item_type = $row['item_type'];
        echo $item_type . "\r\n";
    }
    echo $row["item_name"];
    echo $row["item_size"];
    echo $row["item_desc"];
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12866112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档