query and array syntax

2 part question:
I am using Cold Fusion 4.5
a) how do I refer to a query using 2d array like syntax?
b) what is the best way to populate a 2d array from query result?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hannemanAuthor Commented:
Thanks Hamdy, I am now half the way there...
I still need to know how to refer to a query using array like syntax, so that I do not have to hard code the column names.
The problem that I have at the moment is that I can access the query sort of dynamically, I can put the column names into the array, but not the column values....

This is what I have so far:

<cfset counter=1>
<cfset thedata = ArrayNew(2)>
<cfloop query="data">
<cfset thedata[counter] = ArrayNew(1)>

     <cfset innerloop = 1>
     <cfloop index="listelement" list=#data.columnlist#>
          <cfset #thedata[counter][innerloop]# = #data.columnlist[innerloop]#>
          <cfset innerloop = #innerloop# + 1>
     <CFSET counter = #counter# + 1>

<CFLOOP INDEX="OuterCounter"
    FROM="1" TO="#ArrayLen(thedata)#">

    <CFLOOP INDEX="InnerCounter" FROM="1"



Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

hannemanAuthor Commented:
changed this line:
<cfset #thedata[counter][innerloop]# = #data.columnlist[innerloop]#>

to this:
<CFSET #thedata[counter][innerloop]# = #data[listelement][innerloop]#>
puts the value, not the name in, but it doesnt increment (first row goes into every element in the array)
hannemanAuthor Commented:
<CFSET #thedata[counter][innerloop]# = #data[listelement][counter]#>
Very good.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
if your query is:

<cfquery name="query" datasource="#dsn#">
select col_1,col_2...col_n from table

you can refer to query output as:

query.col_1[i] where i is the row of data you want, and col_1 is the column you want.

A request for deletion or PAQ has been made.  If no response or you feel this is in error, comment.  If no objection, myself or another Moderator will handle this question in three days.

E-E Admin
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation in the Cleanup topic area:

Accept HamdyHassan

Please leave any comments here within the next four days.

EE Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.