Dynamic Array Names
That's fairly complex to explain, so forgive me if I miss some details.
I got a code working for Coldfusion 9, but my host only uses Coldfusion 8, and I'm not in any position to change that (or to change host for that matter).
Now, I've a recipe list, users are able to choose one or several of the recipes and can add it to the "Grocery List", said grocery list is generated from the ingredients of the recipe. It starts out as any "shopping cart" application out there, however following the various tutorials on the subjet I always get stuck in getting the "Ingredients list", these tutorials allow to pass one variable, and hardly anything else.
Furthermore that list may be printed or downloaded via .txt file (to put on my phone), so I need to keep the data.
As explained above whatever I came up with does not work under CF8, so far I modified my code for what follows (note, I know that the "Evalute()" does not receive much love, so I tried to remove them, the ones I left are only because no matter what else I tried it did not work) :
<cfoutput>
<!--- Loop through the first array containing the name of the recipees (that Array is called "ArList") --->
<cfloop from="1" to="#arraylen(arList)#" index="counter">
<!--- calling the Array via a method --->
#arList[counter].Nom.getNom()#</th>
<!--- Check if there is any array containing the Ingredient or if it is empty (just a security to avoid some bugs I encountered). If not, creates the array, each recipe gets his own ingredients based array, this way it is possible to erase unnecessary ingredient from the grocery list--->
<cfif not isdefined ("session.I_#counter#") OR ArrayIsEmpty (Evaluate("session.I_#counter#")) >
<!--- A bit weird to launch the <cfinvoke> here, but it works, the query only returns the ingredients of the recipe at each loop --->
<cfinvoke component="cfc.manoire" method="Display_Ingrid" returnvariable="Display_Ingrid">
<cfinvokeargument name="M_ID" value="#arList[counter].Nom.getM_id()#">
</cfinvoke>
<!--- Initialise the ingredient Array, these are dynamic since I can't predict how many recipees users will choose --->
<cfset VARIABLES["session.I_" & counter] = ArrayNew(1)>
<!--- Loop through the query to populate the Array --->
<cfloop query="Display_ingrid">
<cfset Arrayappend(VARIABLES["session.I_" & counter], structnew())>
<cfset position=arraylen(VARIABLES["session.I_" & counter])>
<cfset VARIABLES["session.I_" & counter][position].I_Nom = #I_Nom#>
<cfset VARIABLES["session.I_" & counter][position].Quantite = #Quantite#>
<cfset VARIABLES["session.I_" & counter][position].Unite = #Unite#>
</cfloop>
</cfif>
<!--- Displaty the Arrays containing the ingredients' list, holds the hyperlink for the delete option. --->
<cfloop from="1" to="#Arraylen(Evaluate('session.I_#counter#'))#" index="val">
#VARIABLES["session.I_" & counter][val].I_Nom#
#VARIABLES["session.I_" & counter][val].Quantite#
#VARIABLES ["session.I_" & counter][val].Unite#
</cfloop>
</cfloop>
</cfoutput>
I get a" Element session.I_1 is undefined in a Java object of type class coldfusion.runtime.VariableScope" at the beginning of the last loop.
I've tried with evaluate() and it has a problem starting [val], that's not something I found to be fairly well documented so I guess there must be something fairly simple and straightforward that completely escaped me.
I'm not set in any direction, so any advice and/or constructive criticism is/are welcome.
Thanks
