Frank,

Yep, you're going down the right track - that'd pretty much copy
elements out of someCollection into your books structure.

An example pulling the "books" from a database:

<cfquery datasource="foo" name="qGetBooks">
  SELECT isbn, author, title
  FROM books
</cfquery>

<!--- To create an array of structs --->
<cfset aBooks = arrayNew(1)>
<cfloop query="qGetBooks">
  <cfset thisBook = structNew()>
  <cfset thisBook.title = qGetBooks.title>
  <cfset thisBook.author = qGetBooks.author>
  <cfset arrayAppend(aBooks, thisBook)>
</cfloop>

<!--- To create a struct indexed by the ISBN --->
<cfset sBooks = structNew()>

<cfloop query="qGetBooks">
  <cfset sBooks[qGetBooks.isbn] = structNew()>
  <cfset sBooks[qGetBooks.isbn].title = qGetBooks.title>
  <cfset sBooks[qGetBooks.isbn].author = qGetBooks.author>
</cfloop>

<!---
You could also use a loop inside of the query loop to loop over the
columnList of the query, moving all fields into the structure
progamattically.  That way, if you needed to add a field, just add it
to your query, and, well, bam.
--->

-joe
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to