Re: Inserting rows into a 2d array

2003-11-18 Thread Ian Skinner
Looks like this may already be answered, but I just got around to playing with this.My solution is very similar, but maybe a bit more streamlined, if you are still just trying to add blank rows for output purposes.

cfset Test = ArrayNew(2)
cfset Test[1][1] = 'Sacramento'
cfset Test[1][2] = 'C001'
cfset Test[2][1] = 'Los Angles'
cfset Test[2][2] = 'C002'
cfset Test[3][1] = 'New York'
cfset Test[3][2] = 'C003'
cfset Test[4][1] = 'Seattle'
cfset Test[4][2] = 'C004'

h3Dump Test Array/h3
cfdump var=#Test#

h3Output Row 4/h3
cfoutput#Test[4][1]# #Test[4][2]#/cfoutput

cfset ArrayInsertAt(Test,3,ArrayNew(1))

h3Dump Test Array After new row added/h3
cfdump var=#test#

h3Output Row 4/h3
cfoutput#Test[4][1]# #Test[4][2]#/cfoutput

The only real difference then the other example, is I don't bother creating a blank placeholder array.Just put the ArraNew(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.

cfset Test[3][1] = first value
cfset Test[3][2] = second value
ect.

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 diminsion array, that each element contains individual one diminsion arrays.Thus you can have different size arrays at each element.Something like this.

1 : Apples Oranges Peaches
2 : Joe Sally Jim Paul Mary Ringo George
3 : 1 2 3 4 5 6 7 8 9 10
4 : Cool
5 : A B C D E F G H I J K L M N O P Q 

Thus you have a 3 element sub-array in position 1, a 7 element sub-array in position 2, a 10 element sub-array in position 3, a 1 element sub-array in position 4 and finally 17 element sub-array in position 5.

This is powerfull stuff, because each sub-element can contain another level of array, thus you can create truely mind boggeling array demeinsions, only limited by memory, performance and sanity.
If you wanted an 11 dimension array {StringTheoryArray[2][3][1][5][7][8][1][9][17][22][4]}, this is perfectly leagle and allowed.May not be advisable, but you can do it. 

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




Re: Inserting rows into a 2d array

2003-11-18 Thread Ian Skinner
Glad you got this to work for you, but just as a last thought.Your method requries 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 leary for something like this on a high trafic page with a large data set.If neither of these apply to this application then you shouldn't have a problem.But it's a trade off to be aware of if used on such a page.

___
Ian Skinner
Web Developer
Sierra Outdoor Recreation
(http://www.SierraOutdoorRecreation.com)
- Original Message - 
From: DougF 
To: CF-Talk 
Sent: Monday, November 17, 2003 9:22 PM
Subject: Re: Inserting rows into a 2d array

Thanks Dave.
Just what I was fishing for... As a visual learner I need an example to help
understand the concept.

Here is what I have come up with. Tested, works, and solved my problem.
-
cfset My2DArray = ArrayNew(2)
cfloop index=row from=1 to=#query.RecordCount#
CFSET My2DArray[row][1] = #query.var_name[row]#
CFSET My2DArray[row][2] = #query.var_id[row]#
CFSET My2DArray[row][3] = #query.var_count[row]#
/cfloop
cfset firstLetter = A
cfset count=1
cfif My2DArray[count][1] NEQ 
cfloop condition=count LTE ArrayLen(My2DArray)
cfif Left(My2DArray[count][1],1) NEQ firstLetter
 cfset firstLetter = left(My2DArray[count][1],1)
 cfset NewElement = ArrayNew(1)
 cfset NewElement[1] = 
 cfset NewElement[2] = 
 cfset NewElement[3] = 
 cfset InsertSuccess = ArrayInsertAt(My2DArray, #count#, NewElement)
/cfif
cfset count = count + 1
/cfloop
/cfif
--
- Original Message - 
From: Dave Watts [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Monday, November 17, 2003 4:46 PM
Subject: RE: Inserting rows into a 2d array

 Something like this might work:

 cfset My2DArray = ArrayNew(2)
 cfset My2DArray[1][1] = outer 1 inner 1
 cfset My2DArray[1][2] = outer 1 inner 2
 cfset My2DArray[2][1] = outer 2 inner 1
 cfset My2DArray[2][2] = outer 2 inner 2

 cfset NewElement = ArrayNew(1)
 cfset NewElement[1] = foo
 cfset NewElement[2] = bar

 cfset rs = ArrayInsertAt(My2DArray, 2, NewElement)

 Note that I haven't tested this, exactly, but something close to this
should
 work. You could also create the element in place, then populate it, I
 suspect.

 Dave Watts, CTO, Fig Leaf Software
 http://www.figleaf.com/
 voice: (202) 797-5496
 fax: (202) 797-5444


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




Re: Inserting rows into a 2d array

2003-11-18 Thread DougF
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]




Re: Inserting rows into a 2d array

2003-11-18 Thread DougF
(sorry sent last message before it was finished)

Thanks Ian,

 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]




RE: Inserting rows into a 2d array

2003-11-18 Thread Ian Skinner
Well, my first suggestion is to combine at least the first two loops.You
should be able to check for the breaks you want, while you are converting
the query to the array, and insert the blank rows at that time.This way,
you don't even need the ArrayInsertAt function.

 
Something like this.

 
cfquery name=getdata/

 
cfset rowCounter = 1
cfset firstLetter = A
cfset dataAry = ArrayNew(2)

 
cfloop query=getdata !--- a bit simplier syntax then your from-to
loop---
 cfif left(getdata.city,1) NEQ firstLetter
cfset dataAry[rowCounter][1] = 
cfset dataAry[rowCounter][2] = 
cfset rowCounter = rowCounter + 1
cfset firstLetter = left(getdata.city,1)
 /cfif 
cfset dataAry[rowCounter][1] = getdata.city
 cfset dataAry[rowCounter[2] = code
 cfset rowCounter = rowCounter + 1
/cfloop

 
That should cut the processing time by about 30% by eliminating one loop.

-- 
Ian Skinner 
Web Programmer 
BloodSource 
www.BloodSource.org 
Sacramento, CA 

-Original Message-
From: DougF [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 18, 2003 10:58 AM
To: CF-Talk
Subject: Re: Inserting rows into a 2d array

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]




Re: Inserting rows into a 2d array

2003-11-17 Thread Calvin Ward
You'll want to use ArrayInsertAt for this: http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functia7.htm

- Calvin
- Original Message - 
From: DougF 
To: CF-Talk 
Sent: Sunday, November 16, 2003 11:06 PM
Subject: Inserting rows into a 2d array

Hi all,

Need some help with inserting rows into a 2d array. As an example I populate
an array with values cityName and LocationID from a query. I then need to
insert a new ROW between row 4 and row 5. In essence shifting rows 5 and
below down one row. I'd thought of appending to the array, then using
ArraySwap to move all elements down one row (need to keep elements in
order), then using ArrayInsertAt to populate the new row at row 5. This
seems like such an inefficient way. Any suggestions?

Thanks,
Doug


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




Re: Inserting rows into a 2d array

2003-11-17 Thread DougF
It was suggested (thanks Chris) that I could insert elements into an array
by using the ArrayInsertAt() function:

Example:
For a 1d array:
cfset ArrayInsertAt(myArray, 5, myValue)

For a 2d arary:
cfset ArrayInsertAt(myArray, 5, ArrayNew(1))
cfset myArray[5][1] = whatever
cfset myArray[5][2] = something_else

Problem is that 'ArrayInsertAt' will insert an element(s), but it will
overwrite what is currently at that location. What I need to do is shift the
rows of the Array down and insert a new row containing the new elements.
This adds to the array content and retains the original content of the
array.

Any ideas?

Doug
- Original Message - 
From: DougF [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Sunday, November 16, 2003 8:06 PM
Subject: Inserting rows into a 2d array

 Hi all,

 Need some help with inserting rows into a 2d array. As an example I
populate
 an array with values cityName and LocationID from a query. I then need to
 insert a new ROW between row 4 and row 5. In essence shifting rows 5 and
 below down one row. I'd thought of appending to the array, then using
 ArraySwap to move all elements down one row (need to keep elements in
 order), then using ArrayInsertAt to populate the new row at row 5. This
 seems like such an inefficient way. Any suggestions?

 Thanks,
 Doug

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




RE: Inserting rows into a 2d array

2003-11-17 Thread Dave Watts
 It was suggested (thanks Chris) that I could insert elements 
 into an array by using the ArrayInsertAt() function:
 
 Example:
 For a 1d array:
 cfset ArrayInsertAt(myArray, 5, myValue)
 
 For a 2d arary:
 cfset ArrayInsertAt(myArray, 5, ArrayNew(1))
 cfset myArray[5][1] = whatever
 cfset myArray[5][2] = something_else
 
 Problem is that 'ArrayInsertAt' will insert an element(s), but 
 it will overwrite what is currently at that location. What I 
 need to do is shift the rows of the Array down and insert a 
 new row containing the new elements. This adds to the array 
 content and retains the original content of the array.

According to the documentation, existing elements should automatically be
shifted up one in position, so you shouldn't be having this problem. What
version of CF are you using?

Alternatively, why not just order the data the way you want it before
building the array? Or, perhaps more importantly, why does the ordering
matter at all? Ideally, in most (but not all) situations, it shouldn't.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

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




Re: Inserting rows into a 2d array

2003-11-17 Thread DougF
Thanks Dave, here is what I've discovered. Further ideas appreciated. Doug
- Original Message - 
From: Dave Watts [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Monday, November 17, 2003 9:16 AM
Subject: RE: Inserting rows into a 2d array

 Alternatively, why not just order the data the way you want it before
 building the array? Or, perhaps more importantly, why does the ordering
 matter at all? Ideally, in most (but not all) situations, it shouldn't.

What I'm trying to do is take a query result with two associated elements
named city_name and locationID. The two elements need to be displayed beside
each other, ordered alphabetically on the city name, with a blank line
between the end of one alpha group and the start of the next group (makes it
much easier to visually scan through a long list). The results will be
displayed in a four column, vertically ordered table. My idea is to insert
blank spacers into the results before the table is dynamically constructed
so that the table formatting is not messed up with the spacers running
horizontally across all four columns of the table.

AAA xxxCCC xxx
AAA xxx
DDD xxx
BBBxxx
BBBxxxEEExxx

CCCxxxFFFxxx

 According to the documentation, existing elements should automatically be
 shifted up one in position, so you shouldn't be having this problem. What
 version of CF are you using?

Using CF5. The way I understand the documentation is that the existing
element is shifted one cell to the right, not up or down. In testing I found
this to be true. The existing element is moved to the right and the new
element is inserted as documentation states. This works whether the array is
1, 2 or 3 dimensional. Previously I thought the ArrayInsertAt was just
overwriting the element but now know it was shifting the existing element to
the right and not creating a new row as I was expecting.

So the problem is that I want insert a new ROW into a 2 dimensional array
not just add a new element (cell) to an existing row. This will create the
spacer between existing elements. Ideas or alternatives appreciated.

!---BEGIN test code for 1d array -
CFSET testArray1 = ArrayNew(1)
 CFSET testArray1[1] = Agness
 CFSET testArray1[2] = Albany
 CFSET testArray1[3] = Arlington
p'testArray1' has #ArrayLen(testArray1)# elements.br
cfloop index=Num from=1 to=#ArrayLen(testArray1)#
#Num##testArray1[Num]#,nbsp;
/cfloop/p
CFSET InsertSuccess1 = ArrayInsertAt(testArray1,3,InsertAt3)
pAfter insert 'testArray1' has #ArrayLen(testArray1)# elements.br
cfloop index=Num1 from=1 to=#ArrayLen(testArray1)#
#Num1##testArray1[Num1]#,nbsp;
/cfloop/p
!---END test code---

!---BEGIN test code 2d array 
CFSET testArray2 = ArrayNew(2)
!--- cfloop index=Num2 from=1 to=3 ---
 CFSET testArray2[1][1] = Agness
 CFSET testArray2[2][1] = Albany
 CFSET testArray2[3][1] = Arlington
CFSET testArray2[1][2] = ID01
CFSET testArray2[2][2] = ID02
CFSET testArray2[3][2] = ID03
!--- /cfloop ---
p'testArray2' has #ArrayLen(testArray2)# elements.br
cfloop index=Num2 from=1 to=#ArrayLen(testArray2)#
#Num2##testArray2[Num2][1]#, #testArray2[Num2][2]#,nbsp;
/cfloop/p
!--- insert new elements---
CFSET ArrayInsertAt(testArray2[3],1,InsertHere)
pAfter insert 'testArray2' has #ArrayLen(testArray2)# elements.br
cfloop index=Num3 from=1 to=#ArrayLen(testArray2)#
#Num3##testArray2[Num3][1]#, #testArray2[Num3][2]#,nbsp;
/cfloop/p
prow 3 contents: #testArray2[3][1]#, #testArray2[3][2]#,
#testArray2[3][3]#/p
!---END test code---
 test results 
'testArray1' has 3 elements.
1 Agness,2 Albany,3 Arlington,

After insert 'testArray1' has 4 elements.
1 Agness,2 Albany,3 InsertAt3,4 Arlington,

'testArray2' has 3 elements.
1 Agness, ID01,2 Albany, ID02,3 Arlington, ID03,

After insert 'testArray2' has 3 elements.
1 Agness, ID01,2 Albany, ID02,3 InsertHere, Arlington,

row 3 contents: InsertHere, Arlington, ID03

--


 Dave Watts, CTO, Fig Leaf Software
 http://www.figleaf.com/
 voice: (202) 797-5496
 fax: (202) 797-5444
- Original Message - 
  It was suggested (thanks Chris) that I could insert elements
  into an array by using the ArrayInsertAt() function:
 
  Example:
  For a 1d array:
  cfset ArrayInsertAt(myArray, 5, myValue)
 
  For a 2d array:
  cfset ArrayInsertAt(myArray, 5, ArrayNew(1))
  cfset myArray[5][1] = whatever
  cfset myArray[5][2] = something_else
 
  Problem is that 'ArrayInsertAt' will insert an element(s), but
  it will overwrite what is currently at that location. What I
  need to do is shift the rows of the Array down and insert a
  new row containing the new elements. This adds to the array
  content and retains the original content of the array.


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




RE: Inserting rows into a 2d array

2003-11-17 Thread Ian Skinner
When I have done displays like this, I put all the display logic in the
code, leaving the data alone.Something along these lines (pseudo code);

 
cfquery name = getdata ...
/cfquery

 
cfset firstLetter = left(getdata.cityName[1])
cfset secColumn = false

 
table
 tr
td
cfoutput query = getdata
cfif firstLetter NEQ left(getdata.cityName,1)
 br/
cfset firstLetter =
left(getdata.cityName,1)
/cfif
#getdata.cityName# #getdata.LocationCode#br/

 
cfif getdata,currentRow GT getdata.recordcount/2 and NOT
secColumn
 /tdtd
 cfset secColumn = true
/cfif
/cfoutput
/td
 /tr
/table

 
This will output pretty close to what you wanted in your example.It will
display the first half of the query in one cell of a two cell row, and the
second half in the other cell. Something like this. I hope the alignment
comes through correctly in the email.

 
xxx 
 
xxx y xxx 
xxx
 
xxx xxx 

 
x 

 
If you want a display a little fancier, with the locations codes lined up in
a column you will have to play with the table(s) a bit.Might be easiest to
nest tables, but if you don't want to, it can be done with a bit more work.

 
HTH

-- 
Ian Skinner 
Web Programmer 
BloodSource 
www.BloodSource.org 
Sacramento, CA 

-Original Message-
From: DougF [mailto:[EMAIL PROTECTED]
Sent: Monday, November 17, 2003 11:08 AM
To: CF-Talk
Subject: Re: Inserting rows into a 2d array

Thanks Dave, here is what I've discovered. Further ideas appreciated. Doug
- Original Message - 
From: Dave Watts [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Monday, November 17, 2003 9:16 AM
Subject: RE: Inserting rows into a 2d array

 Alternatively, why not just order the data the way you want it before
 building the array? Or, perhaps more importantly, why does the ordering
 matter at all? Ideally, in most (but not all) situations, it shouldn't.

What I'm trying to do is take a query result with two associated elements
named city_name and locationID. The two elements need to be displayed beside
each other, ordered alphabetically on the city name, with a blank line
between the end of one alpha group and the start of the next group (makes it
much easier to visually scan through a long list). The results will be
displayed in a four column, vertically ordered table. My idea is to insert
blank spacers into the results before the table is dynamically constructed
so that the table formatting is not messed up with the spacers running
horizontally across all four columns of the table.

AAA xxxCCC xxx
AAA xxx
DDD xxx
BBBxxx
BBBxxxEEExxx

CCCxxxFFFxxx

 According to the documentation, existing elements should automatically be
 shifted up one in position, so you shouldn't be having this problem. What
 version of CF are you using?

Using CF5. The way I understand the documentation is that the existing
element is shifted one cell to the right, not up or down. In testing I found
this to be true. The existing element is moved to the right and the new
element is inserted as documentation states. This works whether the array is
1, 2 or 3 dimensional. Previously I thought the ArrayInsertAt was just
overwriting the element but now know it was shifting the existing element to
the right and not creating a new row as I was expecting.

So the problem is that I want insert a new ROW into a 2 dimensional array
not just add a new element (cell) to an existing row. This will create the
spacer between existing elements. Ideas or alternatives appreciated.

!---BEGIN test code for 1d array -
CFSET testArray1 = ArrayNew(1)
CFSET testArray1[1] = Agness
CFSET testArray1[2] = Albany
CFSET testArray1[3] = Arlington
p'testArray1' has #ArrayLen(testArray1)# elements.br
cfloop index=Num from=1 to=#ArrayLen(testArray1)#
#Num##testArray1[Num]#,nbsp;
/cfloop/p
CFSET InsertSuccess1 = ArrayInsertAt(testArray1,3,InsertAt3)
pAfter insert 'testArray1' has #ArrayLen(testArray1)# elements.br
cfloop index=Num1 from=1 to=#ArrayLen(testArray1)#
#Num1##testArray1[Num1]#,nbsp;
/cfloop/p
!---END test code---

!---BEGIN test code 2d array 
CFSET testArray2 = ArrayNew(2)
!--- cfloop index=Num2 from=1 to=3 ---
CFSET testArray2[1][1] = Agness
CFSET testArray2[2][1] = Albany
CFSET testArray2[3][1] = Arlington
CFSET testArray2[1][2] = ID01
CFSET testArray2[2][2] = ID02
CFSET testArray2[3][2] = ID03
!--- /cfloop ---
p'testArray2' has #ArrayLen(testArray2)# elements.br
cfloop index=Num2 from=1 to=#ArrayLen(testArray2)#
#Num2##testArray2[Num2][1]#, #testArray2[Num2][2]#,nbsp;
/cfloop/p
!--- insert new elements---
CFSET ArrayInsertAt(testArray2[3],1,InsertHere)
pAfter insert 'testArray2' has #ArrayLen(testArray2)# elements.br
cfloop index=Num3 from=1 to=#ArrayLen(testArray2)#
#Num3##testArray2[Num3][1]#, #testArray2[Num3][2]#,nbsp;
/cfloop/p
prow 3 contents: #testArray2[3][1]#, #testArray2[3][2]#,
#testArray2[3][3]#/p
!---END test code---
 test results

Re: Inserting rows into a 2d array

2003-11-17 Thread DougF
A great CF Array learning experience...

The Macromedia documentation skilfully avoids mentioning the manipulation of
multi-dimensioned arrays. It seems that you can create multi-dimensional
arrays but can not manipulate them (like you can with one dimension arrays).
Going to take another look at manipulating with the display logic... sigh.

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




RE: Inserting rows into a 2d array

2003-11-17 Thread Dave Watts
 The Macromedia documentation skilfully avoids mentioning the 
 manipulation of multi-dimensioned arrays. It seems that you 
 can create multi-dimensional arrays but can not manipulate 
 them (like you can with one dimension arrays). Going to take 
 another look at manipulating with the display logic... sigh.

Sure, you can manipulate multi-dimensional arrays. A multi-dimensional array
is simply an array that contains arrays in each position.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

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




Re: Inserting rows into a 2d array

2003-11-17 Thread DougF
Thanks Dave.

Not having much knowledge of CF arrays I'd be interested in examples of how
to go about inserting two associated elements between two other associated
elements arrays.

Example:

[first][1] + [first][2]
[second][1] + [second][2]

[first][1] + [first][2]
[NewElement][1] + [NewElement][2]
[second][1] + [second][2]

-Doug

- Original Message - 
From: Dave Watts [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Monday, November 17, 2003 3:36 PM
Subject: RE: Inserting rows into a 2d array

  The Macromedia documentation skilfully avoids mentioning the
  manipulation of multi-dimensioned arrays. It seems that you
  can create multi-dimensional arrays but can not manipulate
  them (like you can with one dimension arrays). Going to take
  another look at manipulating with the display logic... sigh.

 Sure, you can manipulate multi-dimensional arrays. A multi-dimensional
array
 is simply an array that contains arrays in each position.

 Dave Watts, CTO, Fig Leaf Software
 http://www.figleaf.com/
 voice: (202) 797-5496
 fax: (202) 797-5444

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




RE: Inserting rows into a 2d array

2003-11-17 Thread Dave Watts
 Not having much knowledge of CF arrays I'd be interested in 
 examples of how to go about inserting two associated elements 
 between two other associated elements arrays.
 
 Example:
 
 [first][1] + [first][2]
 [second][1] + [second][2]
 
 [first][1] + [first][2]
 [NewElement][1] + [NewElement][2]
 [second][1] + [second][2]

Something like this might work:

cfset My2DArray = ArrayNew(2)
cfset My2DArray[1][1] = outer 1 inner 1
cfset My2DArray[1][2] = outer 1 inner 2
cfset My2DArray[2][1] = outer 2 inner 1
cfset My2DArray[2][2] = outer 2 inner 2

cfset NewElement = ArrayNew(1)
cfset NewElement[1] = foo
cfset NewElement[2] = bar

cfset rs = ArrayInsertAt(My2DArray, 2, NewElement)

Note that I haven't tested this, exactly, but something close to this should
work. You could also create the element in place, then populate it, I
suspect.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

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




Re: Inserting rows into a 2d array

2003-11-17 Thread DougF
Thanks Dave.
Just what I was fishing for... As a visual learner I need an example to help
understand the concept.

Here is what I have come up with. Tested, works, and solved my problem.
-
cfset My2DArray = ArrayNew(2)
cfloop index=row from=1 to=#query.RecordCount#
 CFSET My2DArray[row][1] = #query.var_name[row]#
 CFSET My2DArray[row][2] = #query.var_id[row]#
 CFSET My2DArray[row][3] = #query.var_count[row]#
/cfloop
cfset firstLetter = A
cfset count=1
cfif My2DArray[count][1] NEQ 
cfloop condition=count LTE ArrayLen(My2DArray)
 cfif Left(My2DArray[count][1],1) NEQ firstLetter
cfset firstLetter = left(My2DArray[count][1],1)
cfset NewElement = ArrayNew(1)
cfset NewElement[1] = 
cfset NewElement[2] = 
cfset NewElement[3] = 
cfset InsertSuccess = ArrayInsertAt(My2DArray, #count#, NewElement)
 /cfif
 cfset count = count + 1
/cfloop
/cfif
--
- Original Message - 
From: Dave Watts [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Monday, November 17, 2003 4:46 PM
Subject: RE: Inserting rows into a 2d array

 Something like this might work:

 cfset My2DArray = ArrayNew(2)
 cfset My2DArray[1][1] = outer 1 inner 1
 cfset My2DArray[1][2] = outer 1 inner 2
 cfset My2DArray[2][1] = outer 2 inner 1
 cfset My2DArray[2][2] = outer 2 inner 2

 cfset NewElement = ArrayNew(1)
 cfset NewElement[1] = foo
 cfset NewElement[2] = bar

 cfset rs = ArrayInsertAt(My2DArray, 2, NewElement)

 Note that I haven't tested this, exactly, but something close to this
should
 work. You could also create the element in place, then populate it, I
 suspect.

 Dave Watts, CTO, Fig Leaf Software
 http://www.figleaf.com/
 voice: (202) 797-5496
 fax: (202) 797-5444

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




RE: Inserting rows into a 2d array

2003-11-17 Thread Joe Eugene
Doug,

I read through the emails but I am not quite understanding what you are
trying to accomplish..
You have a data set like...

locationIDcityName
1AAA
2AA
3BB

You want to take the above and populate into an array and put some spaces
between
A and B sorted? You already have the data sorted from the database..

You can loop through the resultset alphabetically and create a 2D Array,
where each
position only contains the first Aphabet.
cfset my2DArray = arrayNew(2)
my2DArray[1] = will contain all A Starting cityNames or whatever

my2DArray[2][1] = SPACE // IS THIS WHAT YOU WANT?

my2DArray[3] = will contain all B Starting cityNames or whatever

You can simply create a list like
myList = A,nbsp;,B...;

loop over the list and populate your 2 Array

HTH
Joe Eugene
-Original Message-
From: DougF [mailto:[EMAIL PROTECTED]
Sent: Monday, November 17, 2003 7:29 PM
To: CF-Talk
Subject: Re: Inserting rows into a 2d array

Thanks Dave.

Not having much knowledge of CF arrays I'd be interested in examples of
how
to go about inserting two associated elements between two other associated
elements arrays.

Example:

[first][1] + [first][2]
[second][1] + [second][2]

[first][1] + [first][2]
[NewElement][1] + [NewElement][2]
[second][1] + [second][2]

-Doug

- Original Message -
From: Dave Watts [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Monday, November 17, 2003 3:36 PM
Subject: RE: Inserting rows into a 2d array

  The Macromedia documentation skilfully avoids mentioning the
  manipulation of multi-dimensioned arrays. It seems that you
  can create multi-dimensional arrays but can not manipulate
  them (like you can with one dimension arrays). Going to take
  another look at manipulating with the display logic... sigh.

 Sure, you can manipulate multi-dimensional arrays. A multi-dimensional
array
 is simply an array that contains arrays in each position.

 Dave Watts, CTO, Fig Leaf Software
 http://www.figleaf.com/
 voice: (202) 797-5496
 fax: (202) 797-5444


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




Inserting rows into a 2d array

2003-11-16 Thread DougF
Hi all,

Need some help with inserting rows into a 2d array. As an example I populate
an array with values cityName and LocationID from a query. I then need to
insert a new ROW between row 4 and row 5. In essence shifting rows 5 and
below down one row. I'd thought of appending to the array, then using
ArraySwap to move all elements down one row (need to keep elements in
order), then using ArrayInsertAt to populate the new row at row 5. This
seems like such an inefficient way. Any suggestions?

Thanks,
Doug

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