newbie question: storing an array variable into a variable whose data type is not specified
i have function below
<cffunction name="myfunction" access="remote" returntype="any">
<cfargument name="form_data" type="struct">
<!--- variable returned function "result" --->
<cfset result['dept_name'] = "some dept"
<cfset result['dept_num'] = "some dept number"
<!--- run query want find information people having
name "john" , there can n number of people name of john --->
<cfquery dbtype="query" name="printpeople">
select *
people
peoplename = "john"
</cfquery>
<cfset peoplearray=arraynew(1)>
<cfset mycounter = 0 />
<cfloop query="printpeople">
<cfset mycounter = mycounter + 1 />
<cfscript>
arrayappend(peoplearray, #printpeople.empid#);
</cfscript>
<cfscript>
arrayappend(peoplearray, #printpeople.departmentname#);
</cfscript>
<cfscript>
arrayappend(peoplearray, #printpeople.departmentid#);
</cfscript>
<cfscript>
arrayappend(peoplearray, #printpeople.emptitle#);
</cfscript>
</cfloop>
<cfset result['people_info'] = peoplearray <!--- can done? --->
<cfset result['statmsg'] = 'information collected.'>
<cfset result['status'] = true>
<cfreturn result>
</cffunction>
the part <cfset result['people_info'] = peoplearray
attempts store array variable variable data type not specified.
can done?
if not, should do? should define datatype of "result" variable structure, change return type
in function signature structure structure variable
can hold string, integer , array variables?
any suggestions appreciated.
cf loosely typed, on whole there no requirement specify data types thinking ought doing.
and best way answer questions "can done?" try , see happens...
one question: why putting arrayappend() calls in single-line <cfscript> blocks? why not use <cfset> tags, or 1 large <cfscript> block?
--
adam
More discussions in Getting Started
adobe
Comments
Post a Comment