Solved

# Working with Nested Arrays / Structures

Posted on 2003-02-23
Medium Priority
216 Views
I've been trying to create a complex data management system using nested arrays and structures. I've been using the example here:

http://www.macromedia.com/v1/handlers/index.cfm?id=18894&method=full

So far, I understand how to create an array that references a structure like this:

<CFSCRIPT>
MyCart = ArrayNew(1);

OneCD = StructNew();
OneCD.Title = "Cookin at the Plugged Nickel";
OneCD.Artist = "Miles Davis";
OneCD.Genre = "Jazz";
OneCD.Cost = "15.00";
OneCD.Quantity = "1";

AnotherCD = StructNew();
AnotherCD.Atrist = "Billie Holiday";
AnotherCD.Genre = "Blues";
AnotherCD.Cost = "14.00";
AnotherCD.Quantity = "2";

</CFSCRIPT>

The link above also makes reference to a nested array that is more than one level deep. My question is, can someone give me an example of how to build a structure like this?

Customer.ShoppingCart[2].Tracks[3].SongTitle

0
Question by:weeezl
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5

LVL 1

Expert Comment

ID: 8008099
Weeez,

That's way to complicated even if you could figure it out.

<CFSCRIPT>
MyCart = ArrayNew(2);

OneCD = StructNew();
OneCD.Title = "Cookin at the Plugged Nickel";
OneCD.Artist = "Miles Davis";
OneCD.Genre = "Jazz";
OneCD.Cost = "15.00";
OneCD.Quantity = "1";

SongTitle = ArrayNew(2);

Album = StructNew();
Album.Track = "1";
Album.SongTitle = "Stella By Starlight";

MyCart[1][1] = OneCD;
MyCart[1][2] = Album;

</CFSCRIPT>
<cfdump var="#MyCart#">
0

LVL 1

Expert Comment

ID: 8008111
Whoops, that's not right...
0

LVL 1

Expert Comment

ID: 8008386
Whoops, that's not right...
0

LVL 1

Accepted Solution

orangachang earned 600 total points
ID: 8008390
Okay, had my coffee... Here it is...

<CFSCRIPT>
Customer = StructNew();

Tracks = ArrayNew(1);

OneSong = StructNew();
OneSong.Track = "1";
OneSong.SongTitle = "If I Were A Bell";

AnotherSong = StructNew();
AnotherSong.Track = "2";
AnotherSong.SongTitle = "Stella By Starlight";

Customer.ShoppingCart = ArrayNew(1);

OneCD = StructNew();
OneCD.Title = "Cookin at the Plugged Nickel";
OneCD.Artist = "Miles Davis";
OneCD.Genre = "Jazz";
OneCD.Cost = "15.00";
OneCD.Quantity = "1";
OneCD.Tracks = Tracks;

</CFSCRIPT>
<cfdump var="#Customer.ShoppingCart#">
<cfoutput>
#Customer.ShoppingCart[1].Tracks[1].SongTitle#
</cfoutput>
0

LVL 1

Expert Comment

ID: 8008423
The test...

<cfloop index="iTracks" from="1" to="#ArrayLen(Customer.ShoppingCart[1].Tracks)#">
#Customer.ShoppingCart[1].Tracks[iTracks].SongTitle#<br>
</cfloop>
0

LVL 2

Author Comment

ID: 8009339
Wheee!

Thanks for your help. Just learning structs in arrays and I assume it has to drive you crazy for a while before you get it.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
###### Suggested Courses
Course of the Month9 days, 13 hours left to enroll