2-Dimensional Array Question

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default 2-Dimensional Array Question

    This is my first time using an array.

    1. My code seems to work but I need to return a count from each piece of the
    array (the number of each suffix in use--for instance there are 39 parts with
    suffix 00 in use in the database)? I've tried ArrayLen, but I don't believe
    that is returning the accurate results I'm looking for. Can anyone make a
    suggestion as to how I can get an accurate number for each piece of my array?

    2. I have not been able to find an understandable example of a two
    dimensional array, can anyone help me to be sure my array is correct? Or is
    there a better approach????

    I have a table with columnheadings 00 01 02 03... 09 A B C and rows the same
    as the column headings, 00 01 02...09 a b c.

    On my test page I've created the following array Action page code with my
    array:

    <cfset aSfx=ArrayNew(2)>
    <cfset aSfx[1][1]="00">
    <cfset aSfx[1][2]="01">
    <cfset aSfx[1][3]="02">
    <cfset aSfx[1][4]="03">
    <cfset aSfx[1][5]="04">
    <cfset aSfx[1][6]="05">
    <cfset aSfx[1][7]="06">
    <cfset aSfx[1][8]="07">
    <cfset aSfx[1][9]="08">
    <cfset aSfx[1][10]="09">




















    <cfquery name="qRecordCount" datasource="CopyPCN">
    SELECT pcn.ref, pcn.sfx
    FROM pcn
    WHERE 0=0
    ORDER BY sfx
    </cfquery>
    <html>
    <head>
    <title>PID Chart</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>

    <form action="ActionPID.cfm" method="post">

    <table width="100%" border="5" cellspacing="0" cellpadding="2">
    <tr>
    <td>SFX</td>
    <td>0</td>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    <td>5</td>
    <td>6</td>
    <td>7</td>
    <td>8</td>
    <td>9</td>
    <td>A</td>
    <td>B</td>
    <td>C</td>
    <td>D</td>
    <td>E</td>
    <td>F</td>
    <td>G</td>
    <td>H</td>
    <td>I</td>
    <td>J</td>
    <td>K</td>
    <td>L</td>
    <td>M</td>
    <td>N</td>
    <td>O</td>
    <td>P</td>
    <td>Q</td>
    <td>R</td>
    <td>S</td>
    <td>T</td>
    <td>U</td>
    <td>V</td>
    <td>W</td>
    <td>X</td>
    <td>Y</td>
    <td>Z</td>
    </tr>
    <tr>
    <td>0</td>
    <cfoutput query="qRecordCount">
    <td>#TRIM(variables.aSfx[1][1])#</a>
    <br>#ArrayLen(aSfx)#</td>
    <td>#TRIM(variables.aSfx[1][2])#&nbsp;</td>
    <td>#TRIM(variables.aSfx[1][3])#</td>

    FusionRed Guest

  2. Similar Questions and Discussions

    1. 2 dimensional array to dataprovider?
      Hi all, I have the following problem. Somewhere a get data to a 2 dimensional array. Is there any clever way to transform the array to a datagrid...
    2. What's better/faster, passing around and manipulating lists or one-dimensional arrays? Should a CFC argument be a list or a one-dimensional array?
      What's better/faster, passing around and manipulating lists or one-dimensional arrays? Should a CFC argument be a list or a one-dimensional array?
    3. Multi-dimensional Array
      Hi, Array-Question: Suppose you have an array like: <? $invoices=$taxrate; $invoices=a number; ?>
    4. turn xml into 2 dimensional array
      Well, www.php.net seems utterly crashed. Does anyone know how to get an XML stream and turn it into a 2 dimensional array?
    5. How do you sort a 2-dimensional array? I'm stumped!
      $fbArray = array($feedbackCategoryArray => $feedbackCategoryArray); I can't begin to fathom in my befuddled mind how to sort this array $fbArray...
  3. #2

    Default Re: 2-Dimensional Array Question

    I have found that the best way to understand the 2 dimensional array
    is to cfdump it. From your code It doesn't look as though you need to
    use a 2-dimensional array but a single dimension array would do fine.

    A good example of a need for a 2 dimensional array would be a list of
    holidays for employees.

    For example, you have a list of holidays each holiday would be an
    array, and the different characteristics of a holiday would be the
    sub-array (2nd dimension of the array).

    The sub array would be something like: (note that this can also be
    done successfully with a structure but for arguments' sake I'll put in
    a 2-dimensional array)

    <cfscript>
    holidays=ArrayNew(2);

    // Christmas Day; Dec 25, According to US law, if
    // it falls on a Saturday, then the day of leave would be
    // the previous friday, if it falls on a sunday, then
    // the day of leave would be the following Monday

    // The name of the holiday
    holidays[1][1]="Christmas Day";

    // The official date
    holidays[1][2]="Dec 25, 2005 "; // This year it is Sunday

    // The Effective date for Leave
    holidays[1][3]="Dec 26, 2005";

    // An explanation if the effective date is different from the
    // Official date
    holidays[1][4]="Christmas Day, December 25 falls on Sunday.
    For most Federal employees, Monday, December 26, 2005, will be treated
    as a holiday for pay and leave purposes.";

    // New Years DayJanuary 1; According to US law, if
    // it falls on a Saturday, then the day of leave would be
    // the previous friday, if it falls on a sunday, then
    // the day of leave would be the following Monday

    // The name of the holiday
    holidays[2][1]="New Year's Day";

    // The official date
    holidays[2][2]="January 1, 2006 "; // Next year it is Sunday

    // The Effective date for Leave
    holidays[2][3]="January 2, 2006";

    // An explanation if the effective date is different from the
    // Official date
    holidays[2][4]="New Year's Day, January 1 falls on Sunday. For
    most Federal employees, Monday, January 2, 2006, will be treated as a
    holiday for pay and leave purposes.";

    </cfscript>

    Then you could just do a cfloop from 1 to #ArrayLen(holidays)# and
    reference the array as such:

    <cfloop from="1" to="#ArrayLen(holidays)#" index="i">
    Holiday name: #holidays[i][1]#<br>
    Official Date: #holidays[i][2]#<br>
    Effective Date: #holidays[i][3]#<br>
    <em>#holidays[i][4]#</em><br><br>
    </cfloop>

    You may also <cfdump var="#holidays#"> to get a good visual
    interpretation of a 2 dimensional array.



    On Wed, 18 May 2005 21:47:29 +0000 (UTC), "FusionRed"
    <webforumsuser@macromedia.com> wrote:
    >This is my first time using an array.
    >
    > 1. My code seems to work but I need to return a count from each piece of the
    >array (the number of each suffix in use--for instance there are 39 parts with
    >suffix 00 in use in the database)? I've tried ArrayLen, but I don't believe
    >that is returning the accurate results I'm looking for. Can anyone make a
    >suggestion as to how I can get an accurate number for each piece of my array?
    >
    > 2. I have not been able to find an understandable example of a two
    >dimensional array, can anyone help me to be sure my array is correct? Or is
    >there a better approach????
    >
    > I have a table with columnheadings 00 01 02 03... 09 A B C and rows the same
    >as the column headings, 00 01 02...09 a b c.
    >
    > On my test page I've created the following array Action page code with my
    >array:
    >
    > <cfset aSfx=ArrayNew(2)>
    > <cfset aSfx[1][1]="00">
    > <cfset aSfx[1][2]="01">
    > <cfset aSfx[1][3]="02">
    > <cfset aSfx[1][4]="03">
    > <cfset aSfx[1][5]="04">
    > <cfset aSfx[1][6]="05">
    > <cfset aSfx[1][7]="06">
    > <cfset aSfx[1][8]="07">
    > <cfset aSfx[1][9]="08">
    > <cfset aSfx[1][10]="09">
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > <cfquery name="qRecordCount" datasource="CopyPCN">
    > SELECT pcn.ref, pcn.sfx
    > FROM pcn
    > WHERE 0=0
    > ORDER BY sfx
    > </cfquery>
    > <html>
    > <head>
    > <title>PID Chart</title>
    > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    > </head>
    >
    > <body>
    >
    > <form action="ActionPID.cfm" method="post">
    >
    > <table width="100%" border="5" cellspacing="0" cellpadding="2">
    > <tr>
    > <td>SFX</td>
    > <td>0</td>
    > <td>1</td>
    > <td>2</td>
    > <td>3</td>
    > <td>4</td>
    > <td>5</td>
    > <td>6</td>
    > <td>7</td>
    > <td>8</td>
    > <td>9</td>
    > <td>A</td>
    > <td>B</td>
    > <td>C</td>
    > <td>D</td>
    > <td>E</td>
    > <td>F</td>
    > <td>G</td>
    > <td>H</td>
    > <td>I</td>
    > <td>J</td>
    > <td>K</td>
    > <td>L</td>
    > <td>M</td>
    > <td>N</td>
    > <td>O</td>
    > <td>P</td>
    > <td>Q</td>
    > <td>R</td>
    > <td>S</td>
    > <td>T</td>
    > <td>U</td>
    > <td>V</td>
    > <td>W</td>
    > <td>X</td>
    > <td>Y</td>
    > <td>Z</td>
    > </tr>
    > <tr>
    > <td>0</td>
    > <cfoutput query="qRecordCount">
    > <td>#TRIM(variables.aSfx[1][1])#</a>
    > <br>#ArrayLen(aSfx)#</td>
    > <td>#TRIM(variables.aSfx[1][2])#&nbsp;</td>
    > <td>#TRIM(variables.aSfx[1][3])#</td>
    Ro Guest

  4. #3

    Default Re: 2-Dimensional Array Question

    It doesn't look like you're actually using the array - is there a different
    reason you need it?

    You could do the whole thing in the query:

    <cfquery name="qRecordCount" datasource="CopyPCN">
    SELECT pcn.ref, pcn.sfx, COUNT(pcn.sfx) AS sfxCount
    FROM pcn
    GROUP BY pcn.ref, pcn.sfx
    ORDER BY sfx
    </cfquery>

    <table width="100%" border="5" cellspacing="0" cellpadding="2">
    <tr>
    <td>SFX</td>
    <cfoutput query="qRecordCount">
    <td>#sfx#</td>
    </cfoutput>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <cfoutput query="qRecordCount">
    <td>#sfxCount#</td>
    </cfoutput>
    </tr>

    I may be misunderstanding what you're trying to do or there may be other
    mitigating factors but it looks like you're over-complicating the code.

    funkygirlAUCA Guest

  5. #4

    Default Re: 2-Dimensional Array Question

    Many thanks for your response/input to my problem. You're probably correct, I
    may well be over complicating the problem. I've never done anything like this
    before and never seen code that would do what I need. Unfortunately, the code
    you suggested doesn't do what I'm trying to accomplish since part of the output
    I need doesn't exist within the database.

    I'm trying to output the "universe" of part number suffixes, some are used in
    the database and can be queried, many are still available and not in the
    database. So, I'm trying to build a table dynamically and then test the output
    suffix against the database, if a suffix exists, it needs to link to another
    drop-down page of part number existing with that suffix and then that links to
    another page of part number detail.

    If you have any other ideas/input, please let me know. I've been working on
    this one page for three days and not making any headway!

    Red\_/

    FusionRed Guest

  6. #5

    Default Re: 2-Dimensional Array Question

    I've got the following code to build this table (a graphical user table that
    has 1,356 elements, some of which are in the database and some are not, the
    table output=suffixes, will be tested against the database for existence and
    then drill-down to another similar page which will be part numbers):

    <cfset indexstring = "0123456789abcdefghijklmnopqrstuvwxyz">
    <cfloop index="x" from="1" to="36">
    <cfloop index="y" from="1" to="36">
    <cfset newstring=Mid(indexstring, x, 1) & Mid(indexstring, y, 1)>
    <cfset aSfx[x][y]=newstring>
    </cfloop>
    </cfloop>
    <cfquery name="qRecordCount" datasource="CopyPCN">
    SELECT pcn.sfx AS aSfx
    FROM pcn
    ORDER BY sfx
    </cfquery>

    It seems to me that this should build the table I need, but I get a java error:

    Error Occurred While Processing Request
    You have attempted to dereference a scalar variable of type class
    java.lang.String as a structure with members.


    The Error Occurred in C:\CFusionMX\wwwroot\GetEmployee\FormPID.cfm: line 96

    94 : <td>0</td>
    95 : <cfoutput query="qRecordCount" group="sfx" >
    96 : <td>#aSfx[x][y]#</td>
    97 : <td>#aSfx#</td>
    98 : <td>#aSfx#</td>



    Debug tells me nothing that's helpful.

    Have I called this correctl??? I am at my wits end trying to have this one
    page build properly!!!!!;-(

    Red

    FusionRed Guest

  7. #6

    Default Re: 2-Dimensional Array Question

    You are trying to reference aSfx[x][y] inside a loop with the attribute
    query="qRecordCount".

    I believe in such a loop (with the query attribute), the scope looks first to
    this query. So you are referencing the aSfx variable in the query scope, when
    you are meaning to reference the one in the variables scope.

    Prefix the array reference with Variables. in order to reference that variable.

    i.e.
    Line 96 : <td>#Variables.aSfx[x][y]#</td>

    See if that will work for you.

    - Shawn

    shawnwindler Guest

  8. #7

    Default Re: 2-Dimensional Array Question

    Many, many thanks for your input. I tried your suggestion ,unfortunately,.
    I'm still getting the same Java error:

    Occurred While Processing Request
    You have attempted to dereference a scalar variable of type class
    java.lang.Double as a structure with members.


    The Error Occurred in C:\CFusionMX\wwwroot\GetEmployee\FormPID.cfm: line 102

    100 : <cfoutput query="qRecordCount" group="sfx" >
    101 :
    102 : <td>#Variables.aSfx[x][y]#</td>
    103 : <td>#Variables.aSfx[x][y]#</td>


    Any other help/input that I can receive is greatly appreciated.

    Red:-(


    FusionRed Guest

  9. #8

    Default Re: 2-Dimensional Array Question

    I'm going to guess that it happens while you are defining your array. I am not
    positive, but I think it may be because you are using numbers, and it thinks
    you are adding rather than concatenating strings. Add a "" & to the beginning.

    i.e.
    <cfset aSfx[x][y] = "" & newstring>

    Something like that may do the trick.
    Tinker around with it.

    If not, post back and we'll give it another shot.

    - Shawn

    shawnwindler Guest

  10. #9

    Default Re: 2-Dimensional Array Question

    Hi again:

    I tried the suggested code <cfset aSfx[x][y] = "" & newstring> in some
    combinations and still get the same java error:

    You have attempted to dereference a scalar variable of type class
    java.lang.Double as a structure with members.


    The Error Occurred in C:\CFusionMX\wwwroot\GetEmployee\FormPID.cfm: line 102

    100 : <cfoutput query="qRecordCount" group="sfx" >
    101 :
    102 : <td>#Variables.aSfx[x][y]#</td>
    103 : <td>#Variables.aSfx[x][y]#</td>
    104 : <td>#Variables.aSfx[x][y]#</td>

    I wonder if my problem stems from the fact that this is a combination of
    numbers and letters???? All I'm trying to do is pull a number/letter from the
    x axis and from the y axis to create the combinations which go into my
    database.


    FusionRed Guest

  11. #10

    Default Re: 2-Dimensional Array Question

    Are you still creating your array with ArrayNew?

    - Shawn
    shawnwindler Guest

  12. #11

    Default Re: 2-Dimensional Array Question

    HI Shawn:

    Thanks very much for your(s) everyone's help with this--I'm very frustrated
    you can imagine.

    Yes, here the code for my array:

    <cfset indexstring = "0123456789abcdefghijklmnopqrstuvwxyz">
    <cfloop index="x" from="1" to="36">
    <cfloop index="y" from="1" to="36">
    <cfset newstring=Mid(indexstring, x, 1) & Mid(indexstring, y, 1)>
    <cfset aSfx=ArrayNew(2)>
    <cfset aSfx[x][y]=""&newstring>
    </cfloop>
    </cfloop>
    <cfquery name="qRecordCount" datasource="CopyPCN">
    SELECT pcn.sfx AS aSfx
    FROM pcn
    ORDER BY sfx
    </cfquery>

    I got the following error message:

    Error Occurred While Processing Request
    You have attempted to dereference a scalar variable of type class
    java.lang.Double as a structure with members.


    The Error Occurred in C:\CFusionMX\wwwroot\GetEmployee\FormPID.cfm: line 104

    102 : <cfoutput query="qRecordCount" group="sfx" >
    103 :
    104 : <td>#Variables.aSfx[x][y]#</td>
    105 : <td>#Variables.aSfx[x][y]#</td>
    106 : <td>#Variables.aSfx[x][y]#</td>


    Many thanks again.

    Red


    FusionRed Guest

  13. #12

    Default Re: 2-Dimensional Array Question

    Move your ArrayNew declaration outside of (before) the loops.
    You are recreating this array every time through the loop.
    I'd imagine this isn't a good thing.

    - Shawn
    shawnwindler Guest

  14. #13

    Default Re: 2-Dimensional Array Question

    Thanks for of the the input and insight, i figure I'm one step closer to a
    solution. I moved the NewArray outside of the code as follows:

    <cfset aSfx=ArrayNew(2)>
    <cfset indexstring = "0123456789abcdefghijklmnopqrstuvwxyz">
    <cfloop index="x" from="1" to="36">
    <cfloop index="y" from="1" to="36">
    <cfset newstring=Mid(indexstring, x, 1) & Mid(indexstring, y, 1)>
    <cfset aSfx[x][y]=""&newstring>
    </cfloop>
    </cfloop>

    <cfquery name="qRecordCount" datasource="CopyPCN">
    SELECT pcn.sfx AS aSfx
    FROM pcn
    ORDER BY sfx
    </cfquery>

    I'm still getting the following message:

    Error Occurred While Processing Request
    You have attempted to dereference a scalar variable of type class
    java.lang.Double as a structure with members.


    The Error Occurred in C:\CFusionMX\wwwroot\GetEmployee\FormPID.cfm: line 103

    101 : <cfoutput query="qRecordCount" group="sfx" >
    102 :
    103 : <td>#Variables.aSfx[x][y]#</td>
    104 : <td>#Variables.aSfx[x][y]#</td>
    105 : <td>#Variables.aSfx[x][y]#</td>

    Any additional input is gratefully appreciated. Also, I'm beginning to
    wonder if Cold Fusion can build this table this way, is there any other way you
    might do this???? I look at the code I've got and I think it should work, I'm
    at a loss. :-(

    Red



    FusionRed Guest

  15. #14

    Default Re: 2-Dimensional Array Question

    I found mention of this same error occurring with complex data types like
    arrays and structures. The only thing that was said was that you can't output
    complex data types. If this is my problem, how would I output this array???
    Does anyone have any suggestions?

    Red:-c

    FusionRed Guest

  16. #15

    Default Re: 2-Dimensional Array Question

    Right after this piece of code:
    <cfset aSfx=ArrayNew(2)>
    <cfset indexstring = "0123456789abcdefghijklmnopqrstuvwxyz">
    <cfloop index="x" from="1" to="36">
    <cfloop index="y" from="1" to="36">
    <cfset newstring=Mid(indexstring, x, 1) & Mid(indexstring, y, 1)>
    <cfset aSfx[x][y]=""&newstring>
    </cfloop>
    </cfloop>

    Try this:
    <cfloop index="x" from="1" to="36">
    <cfloop index="y" from="1" to="36">
    <cfoutput>aSfx[#x#][#y#]=#aSfs[x][y]#<br></cfoutput>
    </cfloop>
    </cfloop>

    If that doesn't work, then you aren't initializing your array correctly. If it
    does work OK, then what are you doing in between the initialization code and
    the line that's throwing the error.

    Kronin555 Guest

  17. #16

    Default Re: 2-Dimensional Array Question

    Many thanks Kronin. The additional code does output the suffix, but it also
    outputs the array variables, i.e.:

    aSfx[1][1]=00
    aSfx[1][2]=01
    aSfx[1][3]=02
    aSfx[1][4]=03
    aSfx[1][5]=04
    aSfx[1][6]=05
    aSfx[1][7]=06
    aSfx[1][8]=07
    aSfx[1][9]=08
    aSfx[1][10]=09
    aSfx[1][11]=0a
    aSfx[1][12]=0b

    Between the code and the line that's throwing the error there's only a two
    line table (header and output):

    <cfset aSfx=ArrayNew(2)>
    <cfset indexstring = "0123456789abcdefghijklmnopqrstuvwxyz">
    <cfloop index="x" from="1" to="36">
    <cfloop index="y" from="1" to="36">
    <cfset newstring=Mid(indexstring, x, 1) & Mid(indexstring, y, 1)>
    <cfset aSfx[x][y]=""&newstring>
    </cfloop>
    </cfloop>

    <!--- <cfloop index="x" from="1" to="36">
    <cfloop index="y" from="1" to="36">
    <cfoutput>aSfx[#x#][#y#]=#aSfx[x][y]#<br></cfoutput>
    </cfloop>
    </cfloop> --->


    <cfquery name="qRecordCount" datasource="CopyPCN">
    SELECT pcn.sfx AS aSfx
    FROM pcn
    ORDER BY sfx
    </cfquery>

    <html>
    <head>
    <title>PID Chart</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>

    <form action="ActionPID.cfm" method="post">


    <table width="100%" border="5" cellspacing="0" cellpadding="2">
    <tr>
    <td width="6%">SFX</td>
    <td width="3%">0</td>
    <td width="2%">1</td>
    <td width="2%">2</td>
    <td width="2%">3</td>
    <td width="2%">4</td>
    <td width="2%">5</td>
    <td width="2%">6</td>
    <td width="2%">7</td>
    <td width="2%">8</td>
    <td width="2%">9</td>
    <td width="3%">A</td>
    <td width="3%">B</td>
    <td width="3%">C</td>
    <td width="3%">D</td>
    <td width="2%">E</td>
    <td width="2%">F</td>
    <td width="3%">G</td>
    <td width="3%">H</td>
    <td width="2%">I</td>
    <td width="2%">J</td>
    <td width="3%">K</td>
    <td width="2%">L</td>
    <td width="3%">M</td>
    <td width="3%">N</td>
    <td width="3%">O</td>
    <td width="2%">P</td>
    <td width="3%">Q</td>
    <td width="3%">R</td>
    <td width="2%">S</td>
    <td width="2%">T</td>
    <td width="3%">U</td>
    <td width="3%">V</td>
    <td width="3%">W</td>
    <td width="3%">X</td>
    <td width="3%">Y</td>


    <tr>

    <cfloop index="aSfx" from="1" to="36" step="1">
    <cfoutput query="qRecordCount" group="sfx" >
    <td>#Variables.aSfx[x][y]#</td>
    <td>#Variables.aSfx[x][y]#</td>
    <td>#Variables.aSfx[x][y]#</td>
    <td>#Variables.aSfx[x][y]#</td>
    <!--- <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td>
    <td>#aSfx#</td> --->


    </cfoutput>
    </tr>
    </cfloop>


    </table>

    Since this works with the addition of your piece of code, I know the problem
    is in my output request which I had as
    <cfoutput>#Variables.aSfx[x][y]#</cfoutput> Since my string for x and y are
    inside loops, and made equal to aSfx[x][y] I thought that when I called this
    that it would output the data. Can you help me with my final call for this???

    Red.





    FusionRed Guest

  18. #17

    Default Re: 2-Dimensional Array Question

    Your problem is that you're naming alot of things aSfx, which causes confusion
    and headaches.

    Your 2d array is aSfx:
    <cfset aSfx=ArrayNew(2)>

    Your query column is aSfx:
    <cfquery name="qRecordCount" datasource="CopyPCN">
    SELECT pcn.sfx AS aSfx
    FROM pcn
    ORDER BY sfx
    </cfquery>

    And your loop index is aSfx:
    <cfloop index="aSfx" from="1" to="36" step="1">

    The one that's causing the most recent problem is the loop index name.

    First: why are you naming everything the same? You can fix most of your
    problems if you just start using unique names.
    Second: what exactly are you trying to accomplish with that <cfloop
    index="aSfx"> loop?

    What is the contents of sfx in your table?

    Kronin555 Guest

  19. #18

    Default Re: 2-Dimensional Array Question

    Thank you for your help with this. To answer your questions:

    1. The "sfx" are the suffixes of part numbers and that is what the table is
    supposed to produce (1356 elements/suffixes), i.e. 00, 01, etc.

    2. I thought I needed the "asfx" look in order to get the rows to produce. I
    put that in during one of my tests and haven't removed it. If I understand you,
    I don't need that loop????

    3. I haven't given unique names in this case because I get lost in what's
    being called. I have renamed Select sfx AS aSfx to "AS suffix" and renamed the
    "asfx" look to "aSuffix".

    Red

    FusionRed Guest

  20. #19

    Default Re: 2-Dimensional Array Question

    OK, I finally get what you want to do. You don't need a 2d array at all (unless
    for some reason after this table is made, you want to use the counts somewhere
    else).

    <cfquery name="qRecordCount" datasource="CopyPCN">
    SELECT count(pcn.sfx) AS count, sfx
    FROM pcn
    GROUP BY sfx
    </cfquery>

    <table>
    <cfset indexstring = "0123456789abcdefghijklmnopqrstuvwxyz">
    <tr><th>Suffix</th>
    <cfloop index="x" from="1" to="36"> <!--- header loop --->
    <th><cfoutput>#mid(indexstring,x,1)#</cfoutput></th>
    </cfloop>
    </tr>
    <cfloop index="y" from="1" to="36"> <!--- row loop --->
    <tr><th><cfoutput>#mid(indexstring,y,1)#</cfoutput></th>
    <cfloop index="x" from="1" to="36"> <!--- column loop --->
    <cfquery dbtype="query" name="getSuffixCount">
    select count from qRecordCount where sfx =
    '#mid(indexstring,x,1)##mid(indexstring,y,1)#'
    </cfquery>
    <td><cfoutput><cfif getSuffixCount.recordcount eq
    1>#getSuffixCount.count#<cfelse>0</cfif></cfoutput></td>
    </cfloop> <!--- end column loop --->
    </tr>
    </cfloop> <!--- end row loop --->
    </table>

    You might need to reverse the suffixes in the column loop, but everything
    should work (assuming the suffixes in sfx in your table are lowercase, if not,
    change the letters in your indexstring to be uppercase).

    Kronin555 Guest

  21. #20

    Default Re: 2-Dimensional Array Question

    Many thanks for all of your help with this code. The code runs as long as I
    leave out the second query "getSuffixCount", when I comment this out I can get
    the table row and column headers). I get ansyntax error message for this part
    of the code. I've tried to figure out the problem, unsuccessfully.

    It says the element "count" is undefined in "getSuffixCount". I'm just not
    sure if this error goes back to "AS count, sfx" from the original query or is
    having a problem with the aggregate SQL function????

    The error message follows:

    Element COUNT is undefined in GETSUFFIXCOUNT.


    The Error Occurred in C:\CFusionMX\wwwroot\GetEmployee\FormPID.cfm: line 35

    33 : select count(sfx) from qRecordCount where sfx =
    '#mid(indexstring,x,1)##mid(indexstring,y,1)#'
    34 : </cfquery>
    35 : <td><cfoutput><cfif getSuffixCount.recordcount eq
    1>#getSuffixCount.count#<cfelse>0</cfif></cfoutput></td>
    36 : </cfloop> <!--- end column loop --->
    37 : </tr>




    --------------------------------------------------------------------------------

    Please Try The Following:

    Check the CFML Reference Manual to verify that you are using the correct
    syntax.

    Search the Knowledge Base to find a solution to your problem.


    Browser Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
    Remote Address 127.0.0.1
    Referer [url]http://localhost:8500/getemployee/TMPepb58h4314.cfm[/url]
    Date/Time 26-May-05 03:19 PM

    Stack Trace (click to expand)
    at
    cfFormPID2ecfm431405256.runPage(C:\CFusionMX\wwwro ot\GetEmployee\FormPID.cfm:35)



    coldfusion.runtime.UndefinedElementException: Element COUNT is undefined in
    GETSUFFIXCOUNT.
    at coldfusion.runtime.DotResolver.resolve(Unknown Source)
    at coldfusion.runtime.CfJspPage._resolve(Unknown Source)
    at coldfusion.runtime.CfJspPage._resolveAndAutoscalar ize(Unknown Source)

    No matter what I've changed in the seond query, I still get "element count is
    undefined...:

    I am grateful for any ideas/input.

    Red


    FusionRed Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139