First of all, if you're going to be playing with structures and arrays,
make friends with cfscript.  It simplifies the process immensely.  All
those structure functions, I think I use three.

Second, I don't know why your arrayAppend function is not working.

Third, it appears that you're setting both the cat_id and the cat_title as
the value of the key "CAT_ID".  You'd essentially be overwriting yourself
each time the loop cycles.  I think what you might be looking for is to
have the key *be* the catID, as below.  Keep in mind that you *can* use
integers as structure keys, provided you reference the structure in array
notation (using brackets) instead of dot notation.

<cfset aCategory = arrayNew(1)>
<cfloop query="get_categories">
        <cfscript>
                aCategory[get_categories.currentRow] = structNew();
                aCategory[get_categories.currentRow][cat_id] = cat_title;
        </cfscript>
</cfloop>

Sharon

At 02:35 PM 3/28/2001 -0800, Derek Hamilton wrote:
>I was wondering how people have created structures from queries.  I have a
few queries that I run that I want to move into one array of structures so
that I can sort/display them at once instead of three different
sort/displays with each query.  This is what I have done so far:
>    
>    <cfset aCategory = ArrayNew(1)>
>    
>    <cfoutput query="get_Categories">
>    <cfset structCat = StructNew()>
>    <cfset RESULT = InsertStruct(structCat, "CAT_ID", #cat_id#)>
>    <cfset RESULT = InsertStruct(structCat, "CAT_ID", #cat_title#)>
>    <cfset RESULT = ArrayAppend(aCategory, structCat)>
>    </cfoutput>
>
>(I cut out some of the error catching, etc that I do with RESULT.)
>
>The problem I am having is that when I call the ArrayAppend it does append
but I end up with only one element in the array even though there are more
in the resultset.  Does this have to do with the fact that in my cfoutput I
use the same structure name?  Is the structure being copied into the array
by value or by reference?  And, is that what is messing things up?
>
>I hope that my question/problem is clear!
>
>BTW, if anybody has any better ideas for merging 3 or more queries into
one resultset I would love to hear them as I might just be going about this
whole thing wrong.
>
>TIA, 
>
>Derek Hamilton
>Systems Developer
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to