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 に答える