Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

outputting an array 1

Status
Not open for further replies.

daNewfie

Programmer
Oct 14, 2004
258
CA
Im using the following code to output an array on the same page the array is populated.

I am having trouble (ie its not working) on subsequent pages

Code:
<cfoutput query="qInfo">
  <cfif (form["selection_" & groupID] eq productID)>
    <cfset session.arrCustomized[1] = #productCode#> 
	#session.arrCustomized[1]#
  </cfif> 
  
</cfoutput>
 
hi daNewfie,

Does nothing show up on subsequent pages or just the first index in the array?

I'm not sure what it is that you are accomplish, but it lookslike you are only populating the first index of your array, try the following:

Code:
<cfoutput query="qInfo">
  <cfif (form["selection_" & groupID] eq productID)>
    <cfset session.arrCustomized[currentRow] = #productCode#>
    #session.arrCustomized[currentRow]#
  </cfif>  
</cfoutput>

hope this helps,

jalpino
 
Actually, you code and my code produce the same results..

the problem is I did a query and I use that query in the output of the array, how fo I access the info inside the array now on a page without that query

Code:
<cfoutput>
  <cfif (form["selection_" & groupID] eq productID)>
    <cfset session.arrCustomized[currentRow] = #productCode#>
    #session.arrCustomized[currentRow]#
  </cfif>  
</cfoutput>

for instance by taking the query statemnet out of the cfoutput tag
 
daNewfie,

You want to know how to loop through the array and output the results without having to use the 'query object' within <cfoutput>?

Code:
  <!--- Copy your session array to a local scope --->
  <cflock scope="session" type="readOnly" timeout="10">
       <cfset myArray = duplicate(session.arrCustomized)>
  </cflock>

  <!--- Loop through the array and output the results --->
  <cfoutput>
  <cfloop from="1" to="#arraylen(myArray)#" index="i">
     #myArray[i]#
  </cfloop>
  </cfoutput>

I hope this helps,

jalpino
 
This is what Im getting now..I search on the net and cant find anything on it

Error Diagnostic Information

An error occurred while evaluating the expression:


#myArray#


Error near line 235, column 14.
--------------------------------------------------------------------------------

The element at position 3 in dimension 1 of object "myArray" cannot be found. The object has elements in positions 1 through 30. Please, modify the index expression.


The error occurred while processing an element with a general identifier of (#myArray#), occupying document position (235:6) to (235:17).



BTW, thanks for all your help

Craig
 
Hi daNewfie,

It looks like I skewed my logic a little. I noticed that when we are setting the indexes of the array with values, not every index of the array is being populated. The <cfif ..> statement is selectively assigning which indexes receive values. Since 'currentRow' is updated on each iteration of the loop, the iterations that did not meet our condition did not have the corresponding index in the array populated. That is why you were receiving an error when you were trying to output the value at index 3, becasue the 3rd iteration of our loop did not meet the condition and was being skipped. Replace your array assignment code with the following:

Code:
 <cfset indexcount = 1> 
 <cfoutput query="qInfo">
    <cfif (form["selection_" & groupID] eq productID)>
      <cfset session.arrCustomized[indexcount] = productCode>
      <cfset indexcount = indexcount + 1>
    </cfif>  
</cfoutput>

Hope this helps,

jalpino
 
Thanks Jalpino...

Im trying to find how to give a star but I cant find it....


Cheers
Craig
 
This is weird...
when I left friday this was working perfectly now Im getting this error


Error Occurred While Processing Request
Error Diagnostic Information

An error occurred while evaluating the expression:


#myArray#


Error near line 228, column 14.
--------------------------------------------------------------------------------

The element at position 12 in dimension 1 of object "myArray" cannot be found. The object has elements in positions 1 through 30. Please, modify the index expression.


The error occurred while processing an element with a general identifier of (#myArray#), occupying document position (228:6) to (228:17).




 
this is the code

Code:
<cfset indexcount = 1> 
 <cfoutput query="qInfo">
    <cfif (form["selection_" & groupID] eq productID)>
      <cfset session.arrCustomized[indexcount] = productCode>
      <cfset indexcount = indexcount + 1>
    </cfif>  
</cfoutput>

  <cflock scope="session" type="readOnly" timeout="10">
       <cfset myArray = duplicate(session.arrCustomized)>
  </cflock>
 
  <cfoutput>
  <cfloop from="1" to="#arraylen(myArray)#" index="i">
     #myArray[i]#
  </cfloop>
  </cfoutput>
 
hi daNewfie, what was the issue? Anyways, glad that you were able to resolve it.

jalpino
 
Im not 100% sure....

all I did was kill the browser and went back in and it worked...so I think that the session variables were compounding....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top