Jump to content

Grouping columns


immanuelx2

Recommended Posts

Let's say I have a very simple Table:

 

+---------------------+
| id |  name  | level |
+---------------------+
|  1 |  Adam  |   1   |
|  2 |  Jack  |   7   |
|  3 |  Bill  |   1   |
|  4 |  Pete  |   3   |
|  5 |  Ross  |   7   |
+---------------------+

 

but I want the PHP to output their id's and names, but group their Levels together like so:

 

Level 1:
Adam (id: 1)
Bill (id: 3)

Level 3:
Pete (id: 4)

Level 7:
Jack (id: 2)
Ross (id: 5)

 

And then afterwards, If I create someone with a new level, PHP will automatically create a new heading (e.g. Level 10) and put the corresponding names under it.

 

How should I approach this? Should my PHP contain two "while"s? Or do I use the SQL <group by> function? Any help is appreciated!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.