2012-10-12 21 views
-1

因此,這裏是我從查詢得到表:集團通過在頭從SQL查詢PHP

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

我知道是通過一個循環完成的,但無法弄清楚。謝謝!

+2

顯示一些代碼(PHP/SQL ..你試過什麼)。 – Kermit

+0

我不知道從哪裏開始。你不需要投下我的問題。 –

+1

一旦問題顯示出努力並被編輯,我可以刪除我的投票。 – Kermit

回答

3

嘗試按項目類型排序查詢,並在當前標題更改時強制標題。

$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"]; 
} 
+0

非常感謝你的工作很棒。一點格式調整,這正是我需要的。 –