0

所以这是我从查询中得到的表:

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

我想在报告中添加如下内容:

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

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

4

1 回答 1

4

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

$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"];
}
于 2012-10-12T20:10:53.180 回答