Output MySQL dynamically without column names using ColdFusion

Viewed 148

I want to dynamically output a table and it's data. I have the data source and the Table Name.

I was looking at using <cftable> but I am stuck with the dynamic column names.

This is basically what I want to do - it obviously does not work, but here for illustration purposes.

<cfset datasource = "test">
<cfset tablename = "mytable">

<!--- first get the columns from the table --->
<cfquery name="getcolumns" datasource="#datasource#">
SELECT COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = '#mytable#';
</cfquery>

<!--- Now select all from the table --->
<cfquery name="selectall" datasource="#datasource#">
SELECT      *
FROM        #mytable#
</cfquery>

<!--- Output all rows from the table --->
<cftable query="selectall">
  <cfoutput query="getcolumns">
     <cfcol text="#COLUMN_NAME#" header="#COLUMN_NAME#">
</cfoutput>
</cftable>
1 Answers
Related