Ok, I see that you fixed your source code, so here is my answer:
You iterate over the list of columns and try to evaluate each column as if it were the only element in the structure.
However, the query is slightly different: it is referred to as a series of structures, which, in turn, are arrays of each row of data as they return from the query.
If you want to display all rows of data without knowing the columns in front (or dynamically passing them as you mean in your code above), try the following:
<cfoutput query="myQuery"> <cfloop list="#myQuery.ColumnList#" index="thisColumn"> #myQuery[thisColumn][myQuery.CurrentRow]# </cfloop> </cfoutput>
This will give you the result you need. An external cfoutput with a request attribute will iterate over all the rows of data that you received. Then, for each row, you iterate over the list of columns created by the query, and for each column, output the data by specifying a row through myQuery.CurrentRow, which automatically iterates through external output.
I would also take a moment to protect you from trying to avoid loops inside loops and just display your values ββexplicitly:
<cfoutput query="myQuery"> #company# #phone# </cfoutput>
Using this syntax is slightly cheaper than the above loop in a loop.
source share