in reply to Building SQL Query on the fly

I would look at Template Toolkit (one of my all time favorite modules). Say you pushed the results of each colum chosen into an array, and passed that to your template as a hash entry name 'sqldata' you could iterate over it in a template like this:
[% FOREACH item IN sqldata %] <colitem>[% item %]</colitem> [% END %]
This would create <colitem>results from column</colitem> for each column selected.