I have been wondering for this for a long time and haven't found a solution to it yet:
I have a table with records (like first_name, last_name, ...) and each records belongs to a category (field: category). Like: friends, people from work, ... . Doesn't really matter whether the category is 1, 2, 3 or a text, I believe.
Now I would like to display a list of all the persons in the table with the category-title above each time (display only once). Is there a better way than having my sql query sorted by category, looping through all rows and checking if the category has changed or not ? If it has, print new title, if it hasn't just display the next record ?
the output should be something like
FRIENDS
- first person
- second person
COLLEAGUES
- another person
- yet another one ...
- ...