ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 10th, 2005, 12:12 PM
Panther893's Avatar
Panther893 Panther893 is offline
MostarDesigns.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Posts: 834 Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 22 h 27 m 3 sec
Reputation Power: 56
Send a message via MSN to Panther893
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

Reply With Quote
  #2  
Old August 10th, 2005, 12:42 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 25 m 55 sec
Reputation Power: 53
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

Reply With Quote
  #3  
Old August 10th, 2005, 12:48 PM
Panther893's Avatar
Panther893 Panther893 is offline
MostarDesigns.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Posts: 834 Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 22 h 27 m 3 sec
Reputation Power: 56
Send a message via MSN to Panther893
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?

Reply With Quote
  #4  
Old August 10th, 2005, 01:30 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 25 m 55 sec
Reputation Power: 53
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.?

Reply With Quote
  #5  
Old August 10th, 2005, 02:25 PM
Panther893's Avatar
Panther893 Panther893 is offline
MostarDesigns.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Posts: 834 Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 22 h 27 m 3 sec
Reputation Power: 56
Send a message via MSN to Panther893
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.

Reply With Quote
  #6  
Old August 10th, 2005, 02:33 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 25 m 55 sec
Reputation Power: 53
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.

Reply With Quote
  #7  
Old August 10th, 2005, 03:41 PM
Panther893's Avatar
Panther893 Panther893 is offline
MostarDesigns.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Posts: 834 Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 22 h 27 m 3 sec
Reputation Power: 56
Send a message via MSN to Panther893
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.

Reply With Quote
  #8  
Old August 10th, 2005, 04:10 PM
Panther893's Avatar
Panther893 Panther893 is offline
MostarDesigns.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Posts: 834 Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 22 h 27 m 3 sec
Reputation Power: 56
Send a message via MSN to Panther893
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

Reply With Quote
  #9  
Old August 10th, 2005, 04:37 PM
Panther893's Avatar
Panther893 Panther893 is offline
MostarDesigns.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Posts: 834 Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 22 h 27 m 3 sec
Reputation Power: 56
Send a message via MSN to Panther893
Question

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?

Reply With Quote
  #10  
Old August 10th, 2005, 04:58 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 25 m 55 sec
Reputation Power: 53
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()#">

Reply With Quote
  #11  
Old August 10th, 2005, 05:12 PM
Panther893's Avatar
Panther893 Panther893 is offline
MostarDesigns.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Posts: 834 Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 22 h 27 m 3 sec
Reputation Power: 56
Send a message via MSN to Panther893
lol i feel so dumb for leaving that out 'doh' (homer simpson moment) lol, gj on the article A++++++++++++++++++

Reply With Quote
  #12  
Old August 10th, 2005, 05:24 PM
Panther893's Avatar
Panther893 Panther893 is offline
MostarDesigns.com
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Posts: 834 Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level)Panther893 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 22 h 27 m 3 sec
Reputation Power: 56
Send a message via MSN to Panther893
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

Reply With Quote
  #13  
Old August 10th, 2005, 06:29 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 25 m 55 sec
Reputation Power: 53
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() ) />
Comments on this post
Panther893 agrees!

Reply With Quote
  #14  
Old August 11th, 2005, 03:30 AM
Panther893's Avatar
Panther893 Panther893 is offline