|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Array question
Author: Bryan F. Hogan
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32557#163406
Use arrayClear(session.item) or just reset the array <cfset
session.item=arrayNew(2)>
Robert Orlini wrote:
> Thank you. One more ?: How do I clear the array to start over?
Author: Robert Orlini
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32557#163401
Thank you. One more ?: How do I clear the array to start over?
Because arrayLen(session.item) is 0 and your looping from
1-arrayLen(session.item). If your just trying to add an item to the
array from a form post just use the following.
<cfif not isDefined('session.item')>
<cfset session.item=arrayNew(2)>
</cfif>
<cfset arrayLength=arrayLen(session.item)>
<cfset session.item[variables.arrayLength+1][1]='qty'>
<cfset session.item[variables.arrayLength+1][2]='item'>
<cfset session.item[variables.arrayLength+1][3]='price'>
<cfoutput>#arrayLen(session.item)#</cfoutput>
<cfdump var="#session.item#">
_____
Author: Bryan F. Hogan
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32557#163397
Because arrayLen(session.item) is 0 and your looping from
1-arrayLen(session.item). If your just trying to add an item to the
array from a form post just use the following.
<cfif not isDefined('session.item')>
<cfset session.item=arrayNew(2)>
</cfif>
<cfset arrayLength=arrayLen(session.item)>
<cfset session.item[variables.arrayLength+1][1]='qty'>
<cfset session.item[variables.arrayLength+1][2]='item'>
<cfset session.item[variables.arrayLength+1][3]='price'>
<cfoutput>#arrayLen(session.item)#</cfoutput>
<cfdump var="#session.item#">
Author: Robert Orlini
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32557#163393
Why can't I get a display of the fields I'm entering with this array? When I
cfoutput the #arraylen(session.item)# its always 0 (zero).
<CFIF Not IsDefined("Session.item")>
<CFSET session.item = arraynew(2)>
</CFIF>
<CFIF isDefined("form.more.x")>
<CFSET itemcount = arraylen(session.item)>
#arraylen(session.item)#
<CFLOOP from="1" to="#arraylen(session.item)#" index="i" step="1">
<CFSET Session.item[itemcount+1][1]=form.qty>
<CFSET Session.item[itemcount+1][2]=form.item>
<CFSET Session.item[itemcount+1][3]=form.priceeach>
#session.item[i][1]#<br>
#session.item[i][2]#<br>
#session.item[i][3]#<br>
</cfloop>
</cfif>
</CFOUTPUT>
Robert Orlini
HW Wilson
718-588-8400 x2656
ô¿ô
|
May 24, 2012
|
Latest Fusion Authority Articles
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||