You can do that with a single table.
[categories]
categoryID int primary key
CategoryName varchar
parentCat int default (0)
If parentCat is 0, then it is a parent Category, if it has a value, then it
is a subCategory of the specified parent.
Then your query would be for example
<cfquery name="categories">
SELECT categoryID, CategoryName, parentCat
FROM categories
Order by parentCat
</cfquery>
Then to display it you just do a nested loop to get all subcategories for
each parent category.
This will only work if you have nested 1 level.
Otherwise your better off to write a UDF or custom tag to output the list
and then you can infinitely nest by calling itself.
<cfoutput>
<ul>
<cfloop query="categories">
<cfset currentCat = categoryID>
<cfif parentCat EQ 0>
<li>#CategoryName#
<cfloop query="categories">
<cfif parentCat EQ currentCat>
<li>#CategoryName#</li>
</cfif>
</cfloop>
</li>
</cfif>
</ul>
</cfoutput>
--
Russ
-----Original Message-----
From: Doug Brown [mailto:[EMAIL PROTECTED]
Sent: 06 January 2007 00:36
To: CF-Talk
Subject: Question on CFC's
I am not overly familiar with CFC's and need a little help with something.
I have two tables that hold categories and sub categories.
[categories]
categoryID
categoryName
[sub_categories]
SCategoryID
categoryID
SCategoryName
I have a query pulling the main categories, and now I need to pull all the
sub categories that are related to the main ones. What I would like to do is
have a page like so dispursed into 3 or 4 seperate colums
MainCategory
sub,sub,sub,sub,
sub,sub,sub,sub
Here is where I am getting my main cats
<CFFUNCTION name="InitGetAllMCats" access="public" returntype="query"
output="no" hint="Get All Main Categories">
<CFSET var GetAllMCats = "">
<CFQUERY name="GetAllMCats" datasource="#APPLICATION.DB#"
username="#APPLICATION.UN#" password="#APPLICATION.PW#"> SELECT
CategoryID,CategoryName,CategoryImage,CatStatus,pricePerAd
FROM #APPLICATION.DBPRE#Categories
ORDER BY CatPos ASC
</CFQUERY>
<CFRETURN GetAllMCats>
</CFFUNCTION>
Doug B.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:265903
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4