Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

query and array syntax

Posted on 2003-03-24
10
Medium Priority
?
204 Views
Last Modified: 2013-12-24
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?

thanks
-h
0
Comment
Question by:hanneman
9 Comments
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8196140
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8196185
0
 
LVL 4

Author Comment

by:hanneman
ID: 8196753
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)>
<cfoutput>

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



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

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

    <CFOUTPUT>
        <B>[#OuterCounter#][#InnerCounter#]</B>:
        #thedata[OuterCounter][InnerCounter]#<BR>
    </CFOUTPUT>

    </CFLOOP>

</CFLOOP>
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 4

Author Comment

by:hanneman
ID: 8196873
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)
0
 
LVL 4

Author Comment

by:hanneman
ID: 8197002
sorted....
<CFSET #thedata[counter][innerloop]# = #data[listelement][counter]#>
0
 
LVL 9

Accepted Solution

by:
HamdyHassan earned 200 total points
ID: 8197052
Very good.
0
 
LVL 10

Expert Comment

by:substand
ID: 8216100
if your query is:

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

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.

0
 
LVL 1

Expert Comment

by:Computer101
ID: 8362314
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.

Computer101
E-E Admin
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10940826
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.

mrichmon
EE Cleanup Volunteer
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question