On Sun, 27 Mar 2005 17:39:35 -0500, Jim Davis <[EMAIL PROTECTED]> wrote: > > On Sun, 27 Mar 2005 15:06:43 -0500, Andrew Tyrone <[EMAIL PROTECTED]> > > wrote: > > > I might be crazy, but I seem to remember, at least in CF 4.x versions, > > that > > > if you scoped a query column within a cfoutput, it would only output the > > > data in the first row of the query, not the current row, no matter where > > you > > > were in the loop. > > Matt's right here, the basic rule doesn't change depending on scope, it > changes on situation. > > If your looping over the query (with a cfoutput or cfloop using the query > attribute) then doing "queryname.fieldname" will always output the current > row's value.
Right, query.column will get you the value, whether you're using cfquery or cfloop. Without a loop, you'll get the values from the first row of the query, which is a handy shortcut if you've got a one-row query. But, with cfoutput you DO NOT need to prefix the column, whereas with cfloop you do... perhaps not now, but in previous versions of CF you did. That's what Matt was referring to. > If you're not looping over a query then "queryname.fieldname" will always > return the value of the first row as if you said "queryname.fieldname[1]". > > The odd thing is with queries should you use indexed notation you get a > different value. While the value of "queryname.fieldname" is the value of > the first row the value of "queryname["fieldname"]" is actually a reference > the column - essentially a one dimensional array containing all of the rows > values. Well, yeah, it's true... but it's actually a 2-dimensional array, because your column name is the first dimension. I may be being unduly picky, but these are issues where "getting it right" is the same as "getting it to work." When using query["column"][rowNumber], you're effectively treating your entire query as a 2-dimensional array, whereas you're asserting that it treats the individual column as a one-dimensional array. It's a critical distinction, because query.column[1] should work as you've explained it, but it won't. > For most everything you can use this as an array. To get the sum of a query > column, for example, you can do ArraySum(queryname["fieldname"]). > > This is a very powerful feature - but test it first. CFMX had some minor > bugs with this related to the fact that in some cases it counted the array > from zero (as Java) and not from one (as CF). And... something you don't see mentioned very often... this worked as far back as CF 4.x, it's not specifically a Java-derived feature, and I've used it on SQL Server datasets that had spaces in the column names because this treats the first dimension of the array - the column name - as a string, which, being wrapped in quotes, resolves just fine where #spaces in this name# won't work no matter how you try to resolve it. Just another tool in thye boxe... Laterz! J -- Continuum Media Group LLC Burnsville, MN 55337 http://www.web-relevant.com http://www.web-relevant.com/blogs/cfobjective ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:200159 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

