Skip to main content
Participant
March 6, 2010
Answered

Output of an Array

  • March 6, 2010
  • 1 reply
  • 711 views

Hi everybody,

I was just playing with the CFLIB metaheaders and everything works fine for a beginner (http://cflib.org/udf/GetMetaHeaders). Now I see all the results in the cfdump, but I want these results in a cfoutput. How can I work it out, that I can have an output of this array, because I want to save these results in a database?

Any help is appreciated

This topic has been closed for replies.
Correct answer Fernis

thank you so far. I'm sorry, that I didnt' work it out so far. I have something like that:

<cfloop index="ArrayIndex" from="1"
             to="#ArrayLen(res)#">
<cfoutput>#res[ArrayIndex].robots#</cfoutput>
</cfloop>

and I tried several other things, but nothing worked so far. I'm sure, that I'm really close to the solution, but I still make sth. wrong. Maybe you can give me a hint.

thanks...


Did you ever get it working? It's been a while since the last post.

Every res[ArrayIndex] is a structure. You can find the key names with structKeyList(), and proceed from there on.

<cfscript>

for (arrayIndex = 1 ; arrayIndex <= arrayLen(res) ; arrayIndex++)

{

sklist = structKeyList(res[arrayIndex]);

writeOutput(res[arrayIndex][listFirst(sklist)] & " = ");

writeOutput(res[arrayIndex][listLast(sklist)] & "<BR/>");

}

</cfscript>

--

-Fernis - fernis.net - ColdFusion Developer For Hire

1 reply

Inspiring
March 6, 2010

If it's a 1D array, it's a simple loop from 1 to the arraylen.

For 2D arrays, I'd try something like this, and this will only work if there are no blank cells in the array.

<cfset Columns = 1>

<cfset FoundNumCols = false>

<cfloop condition = "FoundNumCols is false">

<cftry>

<cfset x = TheArray[1][Columns]>

<cfset Columns = Columns + 1>

<cfcatch>

<cfset FoundNumCols = true>

closing tags.

Same thing for rows.

<cfoutput>

<cfloop from = 1 to = Rows index = "row">

<cfloop from = 1 to = Columns index = "column">

#TheArray[row][column]

closing tags

Innu696Author
Participant
March 7, 2010

hm, thanks so far, but I didnt' get it exactly.

my array looks like this:

I tried your code with the 2D Arrays, but it didn't work so far How can I make an output loop in this case?

Inspiring
March 7, 2010

My code will work for simple values but you have an array of structures.  Plus it's a 1D array.  I also notice that not all the structures have the same set of keys.

Assuming you know what you want to do with each structure, loop through your array (from 1 to arraylen) and do it with each one.