queryToAssociativeArray
<cffunction name="queryToAssociativeArray" returntype="struct"
output="false" access="public"
hint="This turns a query into an struct of structures.">
<cfargument name="Data" type="query" required="yes" />
<cfargument name="Key" type="string" required="yes" />
<cfscript>
var LOCAL = structNew();
LOCAL.FromIndex = 1;
LOCAL.ToIndex = ARGUMENTS.Data.RecordCount;
// Get the column names as an array.
LOCAL.Columns = listToArray( ARGUMENTS.Data.ColumnList );
LOCAL.ColumnCount = ArrayLen( LOCAL.Columns );
// Create an struct to keep all the objects.
LOCAL.dataStruct = structNew();
// Loop over the rows to create a structure for each row.
for (LOCAL.RowIndex = LOCAL.FromIndex ; LOCAL.RowIndex LTE
LOCAL.ToIndex ; LOCAL.RowIndex = (LOCAL.RowIndex + 1)){
// Create a new structure for this row.
LOCAL.dataStruct[ARGUMENTS.Data[ ARGUMENTS.key ][ LOCAL.RowIndex ]]
= structNew();
// Loop over the columns to set the structure values.
for (LOCAL.ColumnIndex = 1 ; LOCAL.ColumnIndex LTE
LOCAL.ColumnCount ; LOCAL.ColumnIndex = (LOCAL.ColumnIndex + 1)){
// Get the column value.
LOCAL.ColumnName = LOCAL.Columns[ LOCAL.ColumnIndex ];
// Set column value into the structure.
LOCAL.dataStruct[ ARGUMENTS.Data[ ARGUMENTS.key ][ LOCAL.RowIndex
] ][ LOCAL.ColumnName ] = ARGUMENTS.Data[ LOCAL.ColumnName ][
LOCAL.RowIndex ];
}
}
return( LOCAL.dataStruct );
</cfscript>
</cffunction>

There are no comments for this entry.
[Add Comment]