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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays in Cold Fusion

Status
Not open for further replies.

anastasia

Programmer
Dec 13, 2000
111
GB
I am trying to display the contents of an array at the moment the array only displays the last selection that the user has selected the last product id and quantity. I want the user to be able to go back and forth slecting items and then all of the items that the user selected displayed.

Any ideas would be greatly appreciated as this is my first application I have created in Cold Fusion. Thanks

The code I am using is as follows.


This creates the array and gets the product id from the url from the previous page and puts it nto the array.

Details Page

<CFSET session.basket=ArrayNew(2)>
<CFSET session.basket[1][1]=#url.answer#>
<CFSET session.basket[ArrayLen(session.basket)+1][1]=#url.answer#>

The user then goes onto this page. The quantity is put into the array from the previous page.
The quantity if for the product id selected.

Checkout page

<CFSET session.basket[1][2]=#form.quantity#>
<CFSET session.basket[ArrayLen(session.basket)][2]=#form.quantity#>


a loop is then performed but only outputs the last id and quantity selected no others when the user oes back to select other items.

<CFLOOP index=&quot;rowCount&quot; from=&quot;1&quot; to=#ArrayLen(session.basket)#&quot;step=&quot;1&quot;>
<CFOUTPUT>
#session.basket[rowCount][1]#
#session.basket[rowCount][2]#
</CFOUTPUT>
</CFLOOP>

p.s The code is fine there are no errors as regards to coding syntax.





 
? you mean that session.basket always have a lenght of *one element* whatever happen ? how do you fill it ? because the code you've shown is only filling first and last row and with the same value ...
 
thanks Iza for your reply

This is the first time I have created an array in Cold Fusion. I thought that yes I was writing over the first element of the array. I do not want to do this I want to add an id and quantity to the first element and then the second id and quantity to the second element and so on. I know that this code does not do that but I do not know how to change it to make it peform as it should.

Thanks anastasia.
 
you have to think that your array is multidimensionnal array, if i were to &quot;draw&quot; it, i would get this :
array[1][1] array[1][2]
array[2][1] array[2][2]
... ....

so now say the first &quot;col&quot; is for id the 2nd is for quantity, and each &quot;line&quot; is for a different product

-> 1st product ordered, you fill :
array[1][1] with the 1st product id
array[1][2] with the 1st product quantity
-> n-th product ordered, you fill :
array[n][1] with the n-th product id
array[n][2] with the n-th product quantity
here, arraylen(array) returns n-1

now you should be able to go by your own
if not tell me *exactly* what's the point






 
iza thank you for your reply. I have since found out that I should create the Array in my home page, as the way I have created it above is that when the user goes back to that page the array is getting re-created and so wiping out data before. That problem solved, however I still get an error with

#session.basket[rowCount][2]# this does not work it does work. The #session.basket[rowCount][1]# for displaying the id works fine but for the quantity no. I still am using the above code apart from the Array is created on the first page of my site.

Thanks

Anastasia.

p.s I am not a real programmer just a learner.
 
what is not working ? which error do you get ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top