Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto display DB fields

Status
Not open for further replies.

ryanbrand

Programmer
Oct 28, 2003
22
US
Hi,
Is there any way that I can have coldfusion automatically display all the fields that I select?
Example:
select * from mytable

Then have it display all the fields from mytable (in html table format) without having to name them all.

Please let me know.
Ryan
 
For Sql you could try:

<cfquery datasource=#DataBaseName# name="fields">
sp_columns #Trim(tablename)#
</cfquery>
 
Assuming Mytable is the name of your query...

Code:
<TABLE>
  <TR>
    <cfloop list="#mytable.columnlist#" index="i">
      <TD>#i#</TD>
    </cfloop>
  </TR>
  <cfoutput query="myqueryname">
    <TR>
      <cfloop list="#mytable.columnlist#" index="i">
        <TD>#evaluate("mytable." & i)#</TD>
      </cfloop>
    </TR>
  </cfoutput>
</TABLE>

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Thanks a lot. Your loops worked great for me. I had to substitute the query name for the places you had the table name. I also added cfoutput tags around #i# for the column names.

Thank you!
Ryan
 
I've been having issues remembering cfoutput lately in a few answers..

lol...

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top