Skip to main content
Participating Frequently
May 5, 2006
Answered

Outputting Query Results with Unknown Column Names

I have been using this code to grab the column headers from a select * statement. (I never know what table will be queried out of 12,000 or so. I want to loop through the column headers and then the query results in to a web page table.

<cfoutput>
<cfset colHeaderNames = ArrayToList(recordset1.getColumnList())/>
#colHeaderNames#
</cfoutput>

Is there a similar method or any suggestions for outputting the results of the query - now that I know the column headers?
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer
May 5, 2006
If I understand correctly, you can do something like the code below.

9 replies

ctlcalAuthor
Participating Frequently
May 5, 2006
The documentation for "getColumnList" is in the Dreamweaver API Live Docs.
Translate
Participating Frequently
May 5, 2006
Thanks. Since I don't use Dreamweaver it makes sense that I haven't seen this.

Phil
Translate
ctlcalAuthor
Participating Frequently
May 5, 2006
jdeline and vkunirs - This worked great! Thanks for the help!
Translate
Participating Frequently
May 5, 2006
I was unaware of the getColumnList() method so I have been dong it the "hard way", which unfortunately, lists the columns alphabetically. I couldn't find getColumnList() documented in LiveDocs, but nothing surprises me any more.

This other solution is great.

Phil
Translate
Correct answer
May 5, 2006
If I understand correctly, you can do something like the code below.
Translate
ctlcalAuthor
Participating Frequently
May 5, 2006
Thanks for the suggestion, but trying that out it looped through the recordset but just outputted the columnheaders over and over - rather then the field values.
Translate
Participating Frequently
May 5, 2006
Column names and query results in a table. (Good luck with changing the column order )

Phil
Translate