Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputting a structure-of-a-structure

Status
Not open for further replies.

deepatpaul

Programmer
Jul 7, 2004
57
0
0
US
I have a structure that I'm populating with data from a query that has two fields. Here is the query data:


<cfset application.categories = structnew() />
<cfset application.categories = getAllCategories /> (getAllCategories is the name of the query resultset)

getAllCategories returns:

query
CATID CATNAME
1 1 Parts 1
2 2 Parts 2
3 3 Parts 3
4 4 Parts 4
5 5 Parts 5
6 6 Parts 6

How do I loop through a structure that contains this 2-D array?
 
Hi deepatpaul,

Even though you can access your object in the same manner as an associative array (structure), the object is still a query object. Running the function isStruct() will yeild false, so it is not neccessary for you to initialize the variable with an empty structure.

In anycase, here is the syntax that you would use to access your query object in the same manner as a structure:
Code:
  application.categories['columnName'][rowIndex]

Also, even though this is not part of your question I thought that I would point out a more proper way to set your application variable:
Code:
<!--- since you are assigning a value to a shared scope variable, lock it to ensure the itegrity of the data. --->
<cflock scope="application" type="exclusive" timeout="10">
   <cfset application.categories = duplicate(getAllCategories )>
</cflock>

Hope this helps,

jalpino
 
I'm still not understanding exactly the purpose of the duplicate() function is. What is the difference between doing set a = b as opposed to set a = dupblicate(b)?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top