You have a mysql database with a column "group". Group can contain nothing, unique values OR shared values with other similar rows of data within the same group.
How would you fetch all of the rows, sort them by the group column and THEN print a header of the group name for each unique group name? For example, the "group" from above would print out:Group SomeData --------------- red 1 yellow 2 green 3 purple 4 red 5 red 6 red 7 orange 8 green 9
The rows should be sorted by "group". Then each "group" has their own header (header would be a prinout of the group itself) which prints before the sql results.Green 3 9 Orange 8 Purple 4 Red 1 5 6 7 Yellow 2
Groups are dynamic so it can't be hard coded.
My idea:
-----------------------
Fetch the rows of the database and store all groups into a hash. Then from there, do a foreach sort and produce a new SQL query for each key.
It seems like this could work but if there's some odd hundred of unique groups, the overhead of all those queries is probably too pricey.
Any ideas or suggestions?
In reply to mysql sorting by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |