?
Solved

Working with Nested Arrays / Structures

Posted on 2003-02-23
6
Medium Priority
?
216 Views
Last Modified: 2013-12-24
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";

     AddIt = ArrayAppend(MyCart, OneCD);
     
          AnotherCD = StructNew();
          AnotherCD.Title = "Lady in Satin";
          AnotherCD.Atrist = "Billie Holiday";
          AnotherCD.Genre = "Blues";
          AnotherCD.Cost = "14.00";
          AnotherCD.Quantity = "2";
         
     AddIt = ArrayAppend(MyCart, AnotherCD);
</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
Comment
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
  • Learn & ask questions
  • 5
6 Comments
 
LVL 1

Expert Comment

by:orangachang
ID: 8008099
Weeez,

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

How about this:

<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

by:orangachang
ID: 8008111
Whoops, that's not right...
0
 
LVL 1

Expert Comment

by:orangachang
ID: 8008386
Whoops, that's not right...
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 1

Accepted Solution

by:
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";

     AddIt = ArrayAppend(Tracks, OneSong);
     
           AnotherSong = StructNew();
           AnotherSong.Track = "2";
         AnotherSong.SongTitle = "Stella By Starlight";
     
     AddIt = ArrayAppend(Tracks, AnotherSong);
     
     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;

     AddIt = ArrayAppend(Customer.ShoppingCart, OneCD);
     
</CFSCRIPT>
<cfdump var="#Customer.ShoppingCart#">
<cfoutput>
#Customer.ShoppingCart[1].Tracks[1].SongTitle#
</cfoutput>
0
 
LVL 1

Expert Comment

by:orangachang
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

by:weeezl
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

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

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question