Why would you avoid using Evaluate I can think of
a few reasons but I am interested in hearing your
Reasons :)
Jeremy Allen
[EMAIL PROTECTED]
-----Original Message-----
From: Rick Osborne [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 31, 2000 12:42 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: getting data from queries as a structure/array
Yep, this is pretty cool. You can say:
<CFSET foo=myQuery.UniqueID[3]>
As it seems, you will get the UniqueID field of the 3rd row of myQuery. You
can therefore think of a query as a structure of arrays (it isn't, but
that's how you can think of it if that helps you). A common mistake is to
use the (more natural, I think, which is why I don't understand why this is
the wrong way) form of an array of structures. This will not work:
<CFSET foo=myQuery[3].UniqueID><!--- wrong! --->
However, getting back to the point. Since you know that you can access
structures in either of the following ways:
<CFSET bar=myStruct.KeyName><!--- is the same as: --->
<CFSET bar=myStruct["KeyName"]>
And since you know that you can think of a query as a structure of arrays,
you can therefore draw the conclusion that the following will also work:
<CFSET baz=myQuery["UniqueID"][10]>
This leads to some interesting tricks by substituting that hard-coded string
with a variable.
For instance, what if you want to dump a query (comma-delimited), but you
don't know the fieldnames (you are making some dynamic table-extractor or
something). You could loop over the query and use Evaluate(), but I don't
like Evaluate() so I try to use it as little as possible. You could do
this, instead:
<CFSET Fields=myQuery.ColumnList>
<CFOUTPUT>#Fields#,#Chr(13)##Chr(10)#</CFOUTPUT>
<CFLOOP FROM="1" TO="#myQuery.RecordCount#" INDEX="i">
<CFLOOP LIST="#Fields#" INDEX="FieldName">
<CFOUTPUT>#myQuery[FieldName][i]#,</CFOUTPUT>
</CFLOOP>
<CFOUTPUT>#Chr(13)##Chr(10)#</CFOUTPUT>
</CFLOOP>
I'll leave the rest as an exercise to the reader. :)
HTH,
Rick
-----Original Message-----
From: Paul Johnston [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 31, 2000 9:25 AM
To: Cf-Talk
Subject: getting data from queries as a structure/array
I have heard (somewhere and I can't remember where) that you can reference a
query result as if it was a structure or an array or something.
Can someone tell me if this is possible? I am assuming that the query is a
structure of some sort.
Paul
----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.