Anyone know how to...

Use Coldfusion to query a specific table and only return the column names?

Thanks

Every query contains the following:

currentRow - Current row of query that cfoutput is processing.
columnList - Comma-delimited list of the query columns.
RecordCount - Number of records (rows) returned from the query.

So if you have a query that says something like this:

<cfquery name="MyQuery" datasource="#DSN#"> SELECT * FROM Items </cfquery>

You could reference MyQuery.columnlist to get the listing you’re looking for. Your query MUST return at least ONE ROW for this to work.

Thanks hatton,

Now all I need to do is scope the output of a loop.. for instance lets say you have a list

#ThisList#.#i#

This doesnt work… know any way around it?

Thanks

This code works for me…

<cfloop index="i" list=#theList# delimiters=","> <cfoutput>#i#<br></cfoutput> </cfloop>

It works with the quotes (list=“#theList#”) also. I think the problem is the code context you’re providing is wrong: #ThisList#.#i# is not valid.

If you really want to provide context for whatever reason, the correct context is #Variables.i# like this:

<cfloop index="i" list="#theList#" delimiters=","> <cfoutput>#Variables.i#<br></cfoutput> </cfloop>

(The delimiters attribute is optional if you’re using a comma for your delimiter.)

Tim

skypanther,
I get what your saying but the thing is, I want to output the list in my loop, but I need to scope the index (#i#) variable with another variable, so it would like like this #ThisList#.#i# but of course that will error. The other way you suggested errors too because CF will complain about the .i variable in #ThisList.i#

Any other ideas?

coldskool
Are you trying to loop through the columns of the query and return each variable. If so it might be something like this.

SELECT * FROM Items Column #i# = #evaluate("MyQuery.#i#")#

is that what you are trying to do?

Thanks man, that did the trick.