Anyone know how to...

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:
Code:
<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

<CFSET ThisList ="First,Middle,Last">

<CFLOOP Index="i" List="#ThisList#">
#ThisList#.#i#
</CFLOOP>

This doesnt work... know any way around it?

Thanks
 
This code works for me...

Code:
<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:

Code:
<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.

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

<cfset Columns=MyQuery.ColumnList>

<cfloop index="i" list="#Columns#">
<cfoutput>Column #i# = #evaluate("MyQuery.#i#")#</cfoutput><br>
</cfloop>

is that what you are trying to do?
 
Back
Top