I have a two dimensional array. I write 3 values ββto the array during its initialization, and I add the fourth value if the value of the array is not equal to the value passed through the form. Then I want to check if the fourth value exists.
update.cfm
<cfset array = obj.getArray() /> <cfif not StructIsEmpty(form)> <cfloop collection="#form#" item="key"> <cfif left(key,3) eq "ID_"> <cfset number = listLast(key,"_") /> <cfset value = evaluate(0,key) /> <cfloop index="j" from="1" to="#arrayLen(array)#"> <cfif (array[j][1] eq number) and (array[j][3] neq value)> <cfset array[j][3] = value /> <cfset array[j][4] = "true" /> </cfif> </cfloop> </cfif> </cfloop> <cfset obj = createObject("component", "cfc.Obj").init(arg = form.arg, argarray = array) /> <cfset application.objDao.update(obj) />
objDao.cfc update method
<cfset matarray = arguments.obj.getArray() /> <cfloop index="i" from="1" to="#arrayLen(array)#"> <cfquery name="qUpdateAsset" datasource="#variables.instance.dsn#"> UPDATE table SET value = <cfqueryparam value="#matarray[i][3]#" cfsqltype="cf_sql_integer" /> <cfif StructKeyExists(matarray[i],"4")> ,status = 'true' </cfif> WHERE arg = <cfqueryparam value="#arguments.obj.getArg()#" cfsqltype="cf_sql_smallint" /> AND number = <cfqueryparam value="#matarray[i][1]#" cfsqltype="cf_sql_integer" /> </cfquery> </cfloop>
My wrong attempt results in an error:
You tried to dereference a scalar variable of type class coldfusion.runtime.Array as a member structure.
source share