I think that to first thing you must have a class that represent the single row of the query. To example if the result of your query are article you must have a class Article with the proper field. Than for each row you create a Object of type Article and you add it to a array or a vector. Finally you flow the array or the vector
and print this that you interest.
Excuse for my bad english.