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>
                </td><td>
                <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.


xxxxxxx  yyyy    xxxx  yyyy
xxxx yyyy        
xxxxxxx yyyyy    xxxxxxx yyyy
                 xxx  yyyy
xxxx yyyy
xxx yyyy         xxxxxxx yyyy


xxxxx yyyy


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 xxx   CCC xxx
AAA xxx
                  DDD xxx
BBB  xxx
BBB  xxx   EEE  xxx

CCC  xxx   FFF  xxx

> 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")>
<p>After 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")>
<p>After 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>
<p>row 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/ <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]

Reply via email to