House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Search cf-talk

February 09, 2010

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
   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             

Home /  Groups /  ColdFusion Talk (CF-Talk)

Trying to access these array values

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
06/27/2008 11:56 AM

I have a multi dimensioned array. I had no problem creating it, and I can dump it. But now it's time to spit out all the values formatted nicely. I've been havin a hard time gettin this right. Here's how I generated it: <cfoutput query="getchecks">                           <!--- Check this line with a RegEx --->                    <cfif reFindNoCase(getchecks.cr_regextouse, thisLine)>                    <cfset lineNum = lineNum + 1>                     <cfset errorArray[lineNum] = arrayNew(1)>        <cfset errorArray[lineNum][1] = arrayNew(1)>          <cfset errorArray[lineNum][1][1] = arrayNew(1)>           <cfset errorArray[lineNum][1][1][1] = arrayNew(1)>            <cfset errorArray[lineNum][1][1][1][1] = arrayNew(1)>             <cfset errorArray[lineNum][1][1][1][1][1] = arrayNew(1)>             <cfset errorArray[lineNum][1][1][1][1][1] = getchecks.cr_errortitle>             <cfset errorArray[lineNum][1][1][1][1][2] = "Line ##" & sourceLineNum>             <cfset errorArray[lineNum][1][1][1][1][3] = "Source text" & thisLine>             <cfset errorArray[lineNum][1][1][1][1][4] = "Dir" & mySite.directory & "\" & mySite.name>             <cfset errorArray[lineNum][1][1][1][1][5] = getchecks.cr_suggestion>                             </cfif>   </cfoutput>     </cfif> HEre's how I'm trying to output it: <cfoutput>   <cfloop from='1' to='#lineNum#' index='i'>      <cfloop from='1' to='#arrayLen(errorArray)#' index='j'>        <cfloop from='1' to='#arrayLen(errorArray)#' index='k'>          <cfloop from='1' to='#arrayLen(errorArray)#' index='l'>            <cfloop from='1' to='#arrayLen(errorArray)#' index='m'>                                     <cfloop from='1' to='#arrayLen(errorArray)#' index='n'>            #errorArray[i][1][1][1][1][n]#            </cfloop>          </cfloop>         </cfloop>        </cfloop>      </cfloop>     </cfloop> </cfoutput> I'm getting the same values multiple times. Thanks, Will

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
06/27/2008 12:00 PM

You need to add the indexes to your output loops: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
06/27/2008 12:08 PM

>You need to add the indexes to your output loops: > > > Perfect as usual Barney! I was beating my head against the wall trying to make it work for the last 30 mins (ok maybe an hour, so what...). Thank you! Will

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
06/28/2008 07:16 PM

>You need to add the indexes to your output loops: > Barney, I did ok appending a text file with the columns of values of the innermost array, but I'm havin a hard time convert it to a query row. I'm gettin a column count doesnt match error. <cfquery datasource="#dsn#">    insert into tbllog (log_name,  log_time, log_problem, log_linenum, log_sourcetext, log_directoryfile, log_suggestion)    values( <!---   <cffile action="append" file="#form.logPath#" addnewline="yes" output="   Scan Performed: #DateFormat(now(), "m/dd/yyyy")# #TimeFormat(now(), "h:mm tt")#   Page: #name#   ">   --->   <cfloop from='1' to='#lineNum#' index='i'>                   <cfloop from='1' to='#arrayLen(errorArray[i])#' index='j'> <!---  <cffile action="append" file="#form.logPath#" addnewline="yes" output="******************************************************************************************************">   --->               <cfloop from='1' to='#arrayLen(errorArray[i][j])#' index='k'>      <cfloop from='1' to='#arrayLen(errorArray[i][j][k])#' index='l'>       <cfloop from='1' to='#arrayLen(errorArray[i][j][k][l])#' index='m'>        <cfloop from='1' to='#arrayLen(errorArray[i][j][k][l][m])#' index='n'>        <cfset nCtr = nCtr + 1>          <cfloop from="1"  to="#arrayLen(errorArray[i][j][k][l][m][n])#" index="thisItem">                    <cfif len(errorArray[i][j][k][l][m][n])>         <cfif not isNumeric(errorArray[i][j][k][l][m][n])>           <cfqueryparam value="#errorArray[i][j][k][l][m][n]#">           <cfelse>          <cfqueryparam cfsqltype="cf_sql_integer" value="#errorArray[i][j][k][l][m][n]#">       </cfif>                         <cfelse>        NULL        </cfif>        <cfif not nCtr eq 5>        ,        </cfif>              </cfloop>               <!---  <cffile action="append" file="#form.logPath#" addnewline="yes" output="#errorArray[i][j][k][l][m][n]#">  --->        </cfloop>        </cfloop>       </cfloop>      </cfloop>     </cfloop> </cfloop> ) </cfquery> Thanks much, Will

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
06/28/2008 09:13 PM

I got it. It's kinda funkadelic. <cfloop from='1' to='#lineNum#' index='i'> <cfquery datasource="#dsn#">    insert into tbllog (log_name,  log_time, log_problem, log_linenum, log_sourcetext, log_directoryfile, log_suggestion)    values(      '#form.scanname#'    ,    <cfqueryparam cfsqltype="cf_sql_timestamp" value="#createODBCDateTime(now())#">    ,                    <cfloop from='1' to='#arrayLen(errorArray[i])#' index='j'>   <cfset nCtr = nCtr + 1>    <!---  <cffile action="append" file="#form.logPath#" addnewline="yes" output="******************************************************************************************************">   --->               <cfloop from='1' to='#arrayLen(errorArray[i][j])#' index='k'>      <cfloop from='1' to='#arrayLen(errorArray[i][j][k])#' index='l'>       <cfloop from='1' to='#arrayLen(errorArray[i][j][k][l])#' index='m'>        <cfloop from='1' to='#arrayLen(errorArray[i][j][k][l][m])#' index='n'>               <cfif len(errorArray[i][j][k][l][m][n])>                  <cfif n eq 2>           <cfqueryparam cfsqltype="cf_sql_integer" value="#errorArray[i][j][k][l][m][n]#">                     <cfelse>           <cfqueryparam cfsqltype="cf_sql_varchar" value="#errorArray[i][j][k][l][m][n]#">           </cfif>                     <cfelse>          NULL                  </cfif>                  <cfif n neq arrayLen(errorArray[i][j][k][l][m])>           ,         </cfif>                 <!---  <cffile action="append" file="#form.logPath#" addnewline="yes" output="#errorArray[i][j][k][l][m][n]#">  --->        </cfloop>        </cfloop>       </cfloop>      </cfloop>     </cfloop>      ) </cfquery>      </cfloop>


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists