嘿大家。當我試圖學習一些PHP和MySQL時,我遇到了一個我在解決問題時遇到困難的問題。我需要一個PHP腳本來查詢mySQL數據庫的國家,書籍,book_price。這裏是我的DBTABLE:如何將結果分組到php中的子組中
+----+-------+----------+------------------------+
| id |Country|Books | Book_price |
+----+-------+----------+------------------------+
| 1 | USA | Zorro | 10 |
| 2 | USA | Zorro | 20 |
| 3 | USA | Zorro | 50 |
| 4 | USA | Leon | 200 |
| 5 | USA | Leon | 240 |
| 6 | ITALY| Tarzan | 70 |
| 7 | ITALY| Tarzan | 30 |
| 8 | ITALY| Tarzan | 100 |
| 9 | ITALY| Cobra | 300 |
| 10 | ITALY| Cobra | 320 |
| 11 | ITALY| Cobra | 350 |
+----+------+-----------+------------------------+
我想組織基於國家,書籍,共書,總的國家,總計GEN(這是所有國家總的總和),結果顯示這樣的結果:
+----------------------------------------------------+
| USA |
+----------------------------------------------------+
| Zorro 10 |
| 20 |
| 50 |
+----------------------------------------------------+
| Total Zorro: 80 |
+----------------------------------------------------+
| Leon 200 |
| 240 |
+----------------------------------------------------+
| Total Leon:440 |
+----------------------------------------------------+
|Total USA: 520 |
+----------------------------------------------------+
|ITALY |
+----------------------------------------------------+
| Tarzan 70 |
| 30 |
| 100 |
+----------------------------------------------------+
| Total Tarzan:200 |
+----------------------------------------------------+
| Cobra 300 |
| 320 |
| 350 |
+----------------------------------------------------+
| Total Cobra: 970 |
+----------------------------------------------------+
|Total ITALY: 1170 |
+----------------------------------------------------+
|TOTAL GEN: 1690 |
+----------------------------------------------------+
謝謝
對不起 - 錯過了一行。看看我的編輯。線28'$總和= ....'。 – hsz 2010-09-14 11:02:38
謝謝。現在它工作正常。 – 2010-09-14 11:15:48