Queries as Structures


ColdFusion query record sets are complex data types. Although they are neither structures nor arrays, they do have similarities to both. You can refer to a query using the standard queryname.columname syntax, much as with a structure. Yet because there are multiple records within a query, you also can refer to a query as queryname.columname[recordnumber]. Consider the following example:

 <cfquery name="users"          datasource="dsn"> SELECT LastName, Firstname FROM users ORDER BY Lastname, FirstName </cfquery> <!--- <cfloop> through the results ---> <cfloop from="1" to="#users.RecordCount#" index="i">  <cfoutput>  #i#: #users.LastName[i]# #users.FirstName[i]#  </cfoutput><br> </cfloop> 

Here the record set is being treated as if it were a structure of arrays. This syntax makes it possible to directly access database results as needed.



Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net