Thanks Ian,

----- Original Message -----
From: "Ian Skinner" <[EMAIL PROTECTED]>
Sent: Monday, November 17, 2003 11:06 PM
Subject: Re: Inserting rows into a 2d array

> What took me a little to get my head around, when I first learned Cold
Fusion Arrays, is that,
> when you have a two dimension Array, it does not have to be a grid or
table.  It is more proper
> to visualize it as a one dimension array, that each element contains
individual one dimension arrays.
>  Thus you can have different size arrays at each element.

Yes, understanding that each element contains an individual one dimension
array was the ah ha moment for me. Was looking for an example to get it
through my thick head...

> ...don't bother creating a blank placeholder array. Just put the
ArrayNew(1) function as the third parameter
> of the ArrayInsertAt function.  This creates a blank new array at the new
position.  Then, if you later
> decide you need to put data here, you can just use simple assignment.

I need the three elements in the new array or logic that uses the new array
will choke when it hits a non-existence element. At most there are any about
20 inserts on the largest record set processed so I don't it makes much
difference to the speed.

> ...just as a last thought.  Your method requires the code to loop through
all the data three times. Once
> to transfer the data from the query to the array, once to process blank
rows into the array, and a third time
> to display it.  I would be a bit leery for something like this on a high
traffic page with a large data set.

Efficiency is now the challenge. Was suspicious of this and testing
confirmed that record sets of 100 or more were noticeably slower even on
fast development server. Converting to a CFscript helped. Tickcount is still
about 70 ms with record set of 500. Any suggestions to help speed it up?
------------------------------
<cfscript>
My2DArray = ArrayNew(2);
row = 1;
while (row LTE query.RecordCount)
{
  My2DArray[row][1] = query.city_name[row];
  My2DArray[row][2] = query.lcid[row];
  My2DArray[row][3] = query.listingcount[row];
  row = row + 1;
}
firstLetter = "A";
countVar = 1;
// if (ArrayLen(My2DArray) GT 20)
while (countVar LTE (ArrayLen(My2DArray)))
  if (Left(My2DArray[countVar][1],1) NEQ firstLetter)
  {
   firstLetter = left(My2DArray[countVar][1],1);
   NewElement = ArrayNew(1);
   NewElement[1] = "";
   NewElement[2] = "";
   NewElement[3] = "";
   InsertSuccess = ArrayInsertAt(My2DArray, countVar, NewElement);
   countVar = countVar + 1;
  }
  else {countVar = countVar + 1;}
</cfscript>
------------------------

[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to