?
Solved

query and array syntax

Posted on 2003-03-24
10
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

771 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