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

Array trouble 1

Status
Not open for further replies.

calista

Programmer
Jan 24, 2001
545
US
I am having a problem with an array. I create an array(2D), display the elements, select an element for processing(in a FORM tag), pass to a processing page(ACTION page) which updates the element, then return to the display page(using CFLOCATION).

The ACTION page seems to know about the array, because I can display any given element, not just the one I selected, but when I return to the display page, the array no longer exists.

How can I process an array, and have it persist throughout the session while passing it back and forth between pages? URL variables are only good for simple values, not complex values like arrays. I even tried creating the array as a session variable, but that didn't seem to work, either. What should I do? Any suggestions greatly appreciated. Calista :-X
Jedi Knight,
Champion of the Force
 
Hey Calista

Everytime I've done something like this it has been possible to re-create the Array from Queries, which I actually wanted to do to be sure that everything was being updated correctly in the Database. If that is not possible the Session variables should be able to do it. Some other methods would be:

hidden form variables (although this would require an extra click or some javascript voodoo)

Cookies (Most people try to stay away from these)

If there are no security considerations you can also your database to store data and re-query on the next page. Just make another table in your database that has a memo field that you can fill full of whatever. Just be sure to clear it when it is no longer necessary.

Hope something works for you.
 
So, you can take the contents of the array, write it to a database, then query the database to retrieve the contents of the array? Does this work for a two-dimensional array?

What if more than one user is in there at a time? They should each have a unique array.

Also, about session variables, I tried something like this:
Code:
<CFSET Session.MyArray = ArrayNew(2)>
It didn't seem to work, but maybe I was doing something wrong (wouldn't be the first time LOL).

Thanks for your input, I'll keep trying. Calista :-X
Jedi Knight,
Champion of the Force
 
Yes,

you can write an array to a database (it's not fun) You can use ArraytoList (with a 2d array you need to loop through 1D while converting the other D to a List) Set a field in the Database to the SessionID to keep track of multiple users.

But if you can use Session Variables they should work fine.

Make sure your <CFLocation ... has Addtoken=&quot;Yes&quot;

Is the Session variable not making it at all or is it the wrong data or what?
 
Hey Calista,

A trick I sometimes use is to having a <cfinclude> instead of a <cflocation> inside the action page. If the array is available during processing of the form variables in the action page, it will then be available during processing of your main page if you use a <cfinclude template=&quot;formPage.cfm&quot;> after all of your processing is done. This way, you still show the original page because it's included and runs just as if they had been re-directed to it but all variables available to the action page are also available to it.

Hope this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top