Hi Ben,
you can shorten it down a bit and go as many levels deep as you want.
Like this:
<cfquery name="cats" datasource="#Application.DSN#">
... snip ..
</cfquery>
<cfloop query=cats>
<cfif NOT StructKeyExists(allcats, "#cats.category#")>
<cfset allcats["#cats.category#"] = StructNew()>
<cfset allcats["#cats.category#"].created=0>
<cfset allcats["#cats.category#"].catid=cats.acategoryid>
</cfif>
<cfif NOT StructKeyExists(allcats["#cats.category#"],
"#cats.subsection#")>
<cfset allcats["#cats.category#"]["#cats.subsection#"] = StructNew()>
<cfset allcats["#cats.category#"]["#cats.subsection#"].created=0>
<cfset allcats["#cats.category#"]["#cats.subsection#"].catid =
cats.categoryid>
</cfif>
<cfif NOT
StructKeyExists(allcats["#cats.category#"]["#cats.subsection#"],
"#cats.manuf#")>
<cfset
allcats["#cats.category#"]["#cats.subsection#"]["#cats.manuf#"] =
StructNew()>
<cfset
allcats["#cats.category#"]["#cats.subsection#"]["#cats.manuf#"].created=0>
<cfset
allcats["#cats.category#"]["#cats.subsection#"]["#cats.manuf#"].l3catid
= cats.l3catid>
</cfif>
</cfloop>
HTH
Kym K
you wrote:
> Hi,
>
> I'm trying to extend a piece of code in an application and I'm not sure
> what the correct syntax is.
>
> The current code looks like:
>
> <cfquery name="cats" datasource="#Application.DSN#">
> SELECT a.categoryname as category, b.categoryname as subsection,
> b.categoryid, a.categoryid as acategoryid
> FROM categories a, categories b
> WHERE b.levels=2 and b.parentid=a.categoryid
> ORDER BY category,subsection
> </cfquery>
>
> <cfloop query=cats>
> <cfif NOT StructKeyExists(allcats, "#category#")>
> <cfset thecat=StructNew()>
> <cfset thecat.created=0>
> <cfset thecat.catid=#acategoryid#>
> <cfset tmp=StructInsert(allcats, "#category#", #thecat#)>
> </cfif>
> <cfif NOT StructKeyExists(allcats["#category#"], "#subsection#")>
> <cfset thesubcat=StructNew()>
> <cfset thesubcat.created=0>
> <cfset thesubcat.catid=#categoryid#>
> <cfset tmp=StructInsert(allcats["#category#"], "#subsection#",
> #thesubcat#)>
> </cfif>
> </cfloop>
>
> I need to add a 3rd structure level to this, so for each subsection
> there will be 0 or more structures within each subsection.
> Would this be reasonable:
>
> <cfquery name="cats" datasource="#Application.DSN#">
> SELECT a.categoryname as category, a.categoryid as acategoryid,
> b.categoryname as subsection, b.categoryid,
> c.categoryname as manuf, c.categoryid as l3catid
> FROM categories a, categories b, categories c
> WHERE b.levels=2 and b.parentid=a.categoryid
> and c.levels=3 and c.parentid = b.categoryid
> ORDER BY category,subsection
> </cfquery>
>
> <cfloop query=cats>
> <cfif NOT StructKeyExists(allcats, "#category#")>
> <cfset thecat=StructNew()>
> <cfset thecat.created=0>
> <cfset thecat.catid=#acategoryid#>
> <cfset tmp=StructInsert(allcats, "#category#", #thecat#)>
> </cfif>
> <cfif NOT StructKeyExists(allcats["#category#"], "#subsection#")>
> <cfset thesubcat=StructNew()>
> <cfset thesubcat.created=0>
> <cfset thesubcat.catid=#categoryid#>
> <cfset tmp=StructInsert(allcats["#category#"], "#subsection#",
> #thesubcat#)>
> <cfif NOT StructKeyExists(allcats["#category#"], "#subsection#",
> "#manuf#")>
> <cfset l3cat=StructNew()>
> <cfset l3cat.created=0>
> <cfset l3cat.l3catid=#l3catid#>
> <cfset tmp=StructInsert(allcats["#category#"], "#subsection#",
> "#manuf#", #l3cat#)>
> </cfif>
> </cfloop>
>
> What I'm not sure of is the syntax for referencing the allcats in the
> StructKeyExists and the StructInsert functions. Is the above correct, or
> would it be something like:
>
> <cfif NOT StructKeyExists(allcats["#category#", "#subsection#"],
> "#manuf#")>
> <cfset l3cat=StructNew()>
> <cfset l3cat.created=0>
> <cfset l3cat.l3catid=#l3catid#>
> <cfset tmp=StructInsert(allcats["#category#", "#subsection#"],
> "#manuf#", #l3cat#)>
> </cfif>
>
> Or something else entirely?
>
> Thanks much!
>
> --Ben
>
> --
> Ben Conner [EMAIL PROTECTED]
> Web World, Inc. 888-206-6486
> PO Box 1122 480-704-2000
> Queen Creek, AZ 85242
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315072
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4