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]

Reply via email to