下面是我从一个查询中得到的表:
----------+----+-----------+----------------------
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
----------+----+-----+-----+----------------------我知道它是通过一个循环来完成的,但我无法弄清楚它。谢谢!
发布于 2012-10-13 04:10:53
尝试按项目类型对查询进行排序,并在当前标题更改时强制显示标题。
$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"];
}https://stackoverflow.com/questions/12866112
复制相似问题