|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
storing arrays in a session
ok i did some reading and i want to store an array in a session this is what i have so far but im getting an error, here is my code below:
Code:
(i allready have an array called "myArray" setup that holds the contents of the array (ID numbers)) <cfset session.cart_contents = myArray> <cfset newArray = ArrayNew(1)> <cfset temp2 = ArrayAppend(newArray, "#session.cart_contents#")> <cfoutput> <P>The contents of the array are as follows: <p></p> <p>#newArray#</p> </cfoutput> i tried to do a toList function on the array but it gave me an error. basically what i want to do is take the contents of myArray and add it to session.cart_contents then call on that session again and place it in an array so i can have it to display the selected items. anyone know what i mean??? ![]()
__________________
MostarDesigns.com |
|
#2
|
|||
|
|||
|
arrayAppend() only adds a new element to the array. You might try something like arrayInsertArrayAt from cflib.org. But more to the point, why are you doing all this copying and merging of arrays? Why not just keep one array, the session array, and only use that one?
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
||||
|
||||
|
well what im doing is making an online paypal cart, and i want to keep all of the items selected (id numbers of the items) stored in a session, then i want to put it in an array, and then output it to show what items are in the cart, maybe im going about it backwards?
|
|
#4
|
|||
|
|||
|
You might be.
Why not just keep your array as a session variable, where each element is a structure that holds any info you need for each cart item, like itemID, price, etc.? |
|
#5
|
||||
|
||||
|
no just the ID number, but thats what im having trouble with, i know how to build the array and append it, but i dont know how to make an array from a session.
|
|
#6
|
|||
|
|||
|
hmm...I'm not clear on why you can't just make a session variable (maybe called session.cart) which is an array? I do this all the time for shopping carts. Then each cart item could be a structure, something like:
session.cart[1].itemid = "id for item 1" session.cart[1].quantity = "quantity of item 1" session.cart[2].itemid = "id for item 2" session.cart[2].quantity = "quanity for item 2" etc. |
|
#7
|
||||
|
||||
|
maybe do this
ok i got that much but where would i store howmany sessions i have assigned to each thing like this session.cart[1].itemid session.cart[2].itemid session.cart[3].itemid session.cart[4].itemid session.cart[5].itemid session.cart[6].itemid like how to i see what number it goes to, ive never used this way. |
|
#8
|
||||
|
||||
|
never mind after doing alot of searching on google i found this, i think im set to go, thanks for your help.
http://www.builderau.com.au/architect/sdi/0,39024602,20269671,00.htm |
|
#9
|
||||
|
||||
|
ok, i ran into another problem, and because im new to this whole concept im again lost, but i think im on the right track, i get this error when trieing to process my code
Error Occurred While Processing Request Error Diagnostic Information An error occurred while evaluating the expression: session.cart = arrayAppend( session.cart, structNew() ) Error near line 145, column 9. -------------------------------------------------------------------------------- Parameter 1 of function ArrayAppend which is now "arrayNew()" must be an array The error occurred while processing an element with a general identifier of (CFSET), occupying document position (145:3) to (145:65) in the template file O:\Hosted Web Sites\Zlatko.Lakisic\seductionslingerie_biz\www\Application.cfm. Date/Time: 08/10/05 17:29:59 Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) Remote Address: 85.94.128.21 HTTP Referrer: http://www.seductionslingerie.biz/item.cfm?ID=57 Query String: action=add And here is my code below Code:
<cfapplication name="myApplication" sessionmanagement="yes" sessiontimeout="#CreateTimeSpan(0,0,30,0)#" applicationtimeout="#CreateTimeSpan(0,0,30,0)#"> <cflock scope="session" type="exclusive" timeout=50> <cfparam name="session.userid" default="0"> <cfparam name="session.disclaimer" default="0"> <cfparam name="session.cart" default="arrayNew()"> </cflock> <!--BEGIN CART CODE--> <cfif action is "add"> <!--- Append a new element to the array. This element is a new structure. ---> <cfset session.cart = arrayAppend( session.cart, structNew() )> <!--- Set up a variable to hold the array position that we're inserting into. ---> <cfset thisCartItem = arraylen( session.cart )> <!--- Populate the new structure with the item information passed from the form. ---> <cfset session.cart[thisCartItem].itemID = FORM.ID> <cfset session.cart[thisCartItem].itemName = FORM.name> <cfset session.cart[thisCartItem].itemQuantity = FORM.quantity> <cfset session.cart[thisCartItem].itemColor = FORM.color> <cfset session.cart[thisCartItem].itemSize = FORM.size> <cflocation url="cart.cfm"> <cfelseif action is "delete"> <!--- Delete the specified item from the cart. ---> <cfloop index="thisCartItem" from="1" to="#arrayLen( session.cart )#"> <cfif session.cart[thisCartItem].itemID eq FORM.ID> <cfset session.cart = arrayDeleteAt( session.cart, thisCartItem )> </cfif> </cfloop> <cflocation url="cart.cfm"> </cfif> I thought that when i listed the arrayNew() in my session variable up top it would create a new session, or was i wrong? |
|
#10
|
|||
|
|||
|
LOL...that's funny because I wrote that article at Builder as well.
When they published it they left a typo in which I have asked them to fix numerous times but they never did. The problem is simple, this:<cfparam name="session.cart" default="arrayNew()"> needs to be this: <cfparam name="session.cart" default="#arrayNew()#"> |
|
#11
|
||||
|
||||
|
lol i feel so dumb for leaving that out 'doh' (homer simpson moment) lol, gj on the article A++++++++++++++++++
![]() |
|
#12
|
||||
|
||||
|
ok now im getting this error
An error occurred while evaluating the expression: session.cart = arrayAppend( session.cart, structNew() ) Error near line 145, column 9. -------------------------------------------------------------------------------- Parameter 1 of function ArrayAppend which is now "YES" must be an array |
|
#13
|
|||
|
|||
|
Another gotcha when using the array functions is that they don't return an array, then simply update the passed array by reference. (Probably another typo) So just do this:
<cfset arrayAppend( session.cart, structNew() ) /> |
|
#14
|
||
|
|