Just wanted to say Thanks to Tim, and Dave.  I needed to know the order of
things (was it the column id first, or the row number)....

I'll dig into my resources more on treating queries as arrays though.  I'm
going to need some place to point junior programmers to.

Thanks again.

Shawn Grover

ps. (I didn't see your comments as immature Tim.  I woulda done the same -
Dave DOES know a lot, and it would make me feel great if I could ever
correct him on a topic.. but I doubt that would happen - he's too good..
<grins>)

-----Original Message-----
From: Timothy Heald [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 29, 2002 8:12 PM
To: CF-Talk
Subject: RE: Help with using query with [] notation


Hey Dave,

        I have waited for a while for this :)  You can do this:

myQuery['col_id']['rowNumber']

        On CF 4.5 on Solaris at least.  It also works in CFMX on Win 2k.

My test code:

<CFQUERY name="getStuff" datasource="home">
        select * from guestbook
</CFQUERY>
<CFOUTPUT>
<CFLOOP list="#getStuff.columnlist#" index="i">
        <CFLOOP from="1" to="#getStuff.recordCount#" index="ii">
                #getStuff[i][ii]#<br>
        </CFLOOP>
</CFLOOP>

#getStuff['cFirstName'][3]#
</CFOUTPUT>

Tim
-----Original Message-----
From: Dave Watts [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 29, 2002 10:05 PM
To: CF-Talk
Subject: RE: Help with using query with [] notation


> I know it's possible to do something like this:
>     MyQuery["FieldName"]  (I know it's probably wrong, but
> serves the purpose here)

For the record, you can't do that, but you can do this:

MyQuery.FieldName[i]

to reference the column value at row i.

> The CF Documentation does mention this somewhere, but doesn't
> really go into detail. Does anyone know of any good links,
> articles, or resources that describe this in more detail???
> I'd prefer to understand this properly, rather than just find
> the "solution" for my current situation. Not to mention that
> it would be better if I can direct my coworkers and
> subordinates to these resources as well....

The only mention of it of which I'm aware is in the "Advanced ColdFusion
Development" course offered by MM, but I suspect it's in the docs somewhere.
However, there really isn't that much else to say about it, beyond the three
lines near the top of the message. You can reference a column's value for a
specific row using array notation.

Of course, how you use this is up to you. For example, if you wanted to
refer to the last row of a recordset, you could do it like this:

MyQuery.FieldName[MyQuery.RecordCount]

Or, you could use this feature to loop over the recordset in a CFSCRIPT
block, since there's nothing analogous to the QUERY attribute of CFOUTPUT
within CFSCRIPT:

<cfscript>
for (i = 1; i lte MyQuery.RecordCount; i = i + 1) {
        WriteOutput(MyQuery.FieldName[i] & "<br>");
}
</cfscript>

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444


______________________________________________________________________
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to