macromedia.coldfusion.cfml_general_discussion
[Top] [All Lists]

Re: Array argument array return

Subject: Re: Array argument array return
From: Ian Skinner
Date: Tue, 04 Mar 2008 08:38:57 -0800
Newsgroups: macromedia.coldfusion.cfml_general_discussion


C-Rock wrote:
I'm using Flash remoting and I've only been able to use very simple CF code in the past. Now I need to pass my function an array as an argument and them search the database and return the query a nested array. I have a database that I need to pass an array of numbers which are ids (these are ids of sales people) in the database. For each one I need to check a column for a number and all the numbers for this id up. So each sold contract has its own line in the database. The sales person's id is a column in the database. I'm just counting the number of contract this person has made. I can do this one by one and then add in flash but it's not very efficent.

So my resulting array returned should be something like this: (sales person id, number of contracts)
 array item [0][0] = 17  - sales id
 array item [0][1] = 4   - contracts sold
 array item [1][0] = 29  - sales id
 array item [1][1] = 2   - contracts sold

 Can anyone point me in the direction of how I would set this up in CF?

 Thanks


<cfscript>
  arrayItems = arrayNew(2);
  arrayItems[1][0] = 17;
  arrayItems[1][1] = 4;
  arrayItems[2][0] = 29;
  arrayItems[2][1] = 2;
</cfscript>

Of course you would probably do this with some kind of loop over the record set return from you database query.

I would also tend to use a structure (associative array) as I find them more descriptive.

<cfscript>
  arrayItems = arrayNew(1);
  arrayItems[1] = structNew(); //technically not required but good form.
  arrayItems[1]["salesID"] = 17;
  arrayItems[1]["contracts"] = 4;
  arrayItems[2] = structNew();
  arrayItems[2]["salesID"] = 29;
  arrayItems[2]["contracts"] = 2;
</cfscript>

Note: that ColdFusion arrays do not start with an index of 0, they start with 1.




<Prev in Thread] Current Thread [Next in Thread>