yep, what you are actually doing is creating a named struct (hash) when you do this:
<cfset result['people_info'] = peoplearray /> changing the return type will give you exactly what you want (unless you want an array), and if you do then you can create an array of structs... On Thu, Sep 9, 2010 at 9:51 AM, Chris H <[email protected]> wrote: > Hi All, > > I am a newbie to Coldfusion. My development background is mainly in C/C++ > so please excuse me if my below question is naive. > > I have a function as below > > <cffunction name="myfunction" access="remote" returntype="any"> > <cfargument name="form_data" type="struct"> > > <!--- The variable to be returned by the function is "result" ---> > > <cfset result['dept_name'] = "some dept" > <cfset result['dept_num'] = "some dept number" > > <!--- I run a query where I want to find some information about people > having > name "John" and there can be N number of people with the name of John ---> > > > <cfquery dbtype="query" name="printPeople"> > SELECT * > FROM people > WHERE 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 this > be done? ---> > > <cfset result['statMsg'] = 'Information successfully > collected.'> > <cfset result['status'] = true> > > <cfreturn result> > > </cffunction> > > > The part <cfset result['people_info'] = peoplearray > attempts to store an array variable into a variable whose data type is not > specified. > > Can this be done? > > If not, what should I do? Should I define the datatype of "result" variable > as a structure, change the return type > in function signature as a structure from any as a structure variable > can hold string, integer and array variables? > > Any suggestions would be appreciated. > > > ------------------------------------------------------------- > To unsubscribe from this list, manage your profile @ > http://www.acfug.org?fa=login.edituserform > > For more info, see http://www.acfug.org/mailinglists > Archive @ http://www.mail-archive.com/discussion%40acfug.org/ > List hosted by FusionLink <http://www.fusionlink.com> > ------------------------------------------------------------- -- Steve Ross web application & interface developer http://blog.stevensross.com [mobile] (912) 344-8113 [ AIM / Yahoo! : zeriumsteven ] [googleTalk : nowhiding ]
