Thank you Jim! You realize though that you have said Ben Forta is wrong...I
wouldn't be standing in the middle of any fields during a thunderstorm if I
were you. :-)

jon
----- Original Message -----
From: "Jim McAtee" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Friday, October 06, 2000 3:21 AM
Subject: Re: accessing a query as an array


> > I am trying to populate an array from a query and I am running into =
> > problems...
> >
> > From what I have infered from the CF docs, CFQuery's are actually =
> > arrays.=20
> > If we assume that then, #QueryName[1][4]# should return the data in the
=
> > first row and the fourth column......right??
> >
> > My confusion comes from what seems to me to be conflicting info in Ben =
> > Forta's book and the CF online docs.=20
> > Ben states on page 529 (4.0) that "Database queries returned by the =
> > <CFQUERY> tag are actually 2D arrays..."
> > The online docs say that "Query column data can be referenced using =
> > array-like syntax. For example, myquery.col_name[1] references data in =
> > the first row in the column col_name."
> >
> > If the latter is true then it seems to me that queries are not acutally
=
> > true 2D arrays but "arraylike" as it says...
>
>
> Internally, queries are probably stored very much like two-dimensional
> arrays.  I don't believe CF lets you address them like this, however.  One
> of the problems is that there's no set order for the columns returned by a
> SQL query.  That should be a bit more obvious when you do a SELECT *.
Which
> database column would you expect the fourth column of the array to be?
>
> CF _will_ let you address each column as a one-dimensional array, as
you've
> shown.  Doing this lets you address the Nth row of the query randomly,
> rather than having to step through the query using <cfloop>.
>
> One simple way to populate a two-d array from a query is shown below.
This
> way, you _know_ that 'name' is the first column, 'address' is the seconde,
> etc.
>
> <cfset a = ArrayNew(2)>
> <cfloop query="myquery">
>   <cfset a[myquery.currentrow, 1] = myquery.name>
>   <cfset a[myquery.currentrow, 2] = myquery.address>
>   <cfset a[myquery.currentrow, 3] = myquery.city>
>   <cfset a[myquery.currentrow, 4] = myquery.state>
>   <cfset a[myquery.currentrow, 5] = myquery.zip>
> </cfloop>
>
> Depending on what you need to do with your array, you might also use an
> array of structs to keep the query results.  An array of structs lets you
> address the columns by name, rather than by column number.  Then again,
> there's no reason why you can't leave the data in the original CF query.
> There are CF function to let you manipulate the query data by adding rows,
> adding columns, and changing values.
>
> Jim
>
> --------------------------------------------------------------------------
----
> 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.

Reply via email to