take a look at this thread.
http://cookbooks.adobe.com/post_Create_nested_lists_from_a_recordset__PHP_-16720.html
I have used this approach a number of times and it is quite straightforward once you get familiar with it, and it shows how to do it with tables and lists.
You only need one recordset, just ensure your data is ordered correctly.
What you are doing is looking at the value of the field which is repeated, if it is the different the previous one, display it, otherwise skip it.