Skip to content

Instantly share code, notes, and snippets.

@nastanford
Created August 21, 2013 13:17
Show Gist options
  • Save nastanford/6294328 to your computer and use it in GitHub Desktop.
Save nastanford/6294328 to your computer and use it in GitHub Desktop.
Query to array of Structures
<cffunction name="querytoarray" returntype="array" output="No">
<cfargument name="q" required="Yes" type="query">
<cfset var aTmp = arraynew(1)>
<cfif q.recordcount>
<cfloop query="q">
<cfset stTmp = structNew()>
<cfloop list="#lcase(q.columnlist)#" index="col">
<cfset stTmp[col] = q[col][currentRow]>
</cfloop>
<cfset arrayAppend(aTmp,stTmp)>
</cfloop>
<cfelse>
<cfset stTmp = structNew()>
<cfloop list="#lcase(q.columnlist)#" index="col">
<cfset stTmp[col] = "">
</cfloop>
<cfset arrayAppend(aTmp,stTmp)>
</cfif>
<cfreturn aTmp>
</cffunction>
<cfset aRecordset= querytoarray(qRecordset)>
<cfdump var="#aRecordset#">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment