immanuelx2 Posted May 30, 2007 Share Posted May 30, 2007 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 https://forums.phpfreaks.com/topic/53601-grouping-columns/ Share on other sites More sharing options...
Wildbug Posted May 30, 2007 Share Posted May 30, 2007 Use "ORDER BY level,name,id" (The name,id part isn't necessary, but it will produce consistent, predictable results.) Link to comment https://forums.phpfreaks.com/topic/53601-grouping-columns/#findComment-265004 Share on other sites More sharing options...
Barand Posted May 30, 2007 Share Posted May 30, 2007 Read the forum guidelines and don't double post your questions. This topic closed. Link to comment https://forums.phpfreaks.com/topic/53601-grouping-columns/#findComment-265227 Share on other sites More sharing options...
Recommended Posts