Hi I have table where i want to display the categories with parent id 0 and When parent id is 1 or 2 and so on...
it should display as :
autos/auto1 autos/cars
Etc:
My database table is like this:
cid int(11) No auto_increment parentid int(11) No 0 img varchar(30) latin1_swedish_ci No title varchar(40) latin1_swedish_ci No cdesc text latin1_swedish_ci No hits
Currently it is diaplying straight as:
categories and after finish of main categories .
sub ategories start.
i am using the query as;
select cid, title, parentid from grcat order by cid
<cfif thisTag.executionMode eq "Start"> <!--- get al the categories that have a parentID defined ---> <cfquery name="qGetCategories" datasource="#request.dsn#"> select categoryID, category from categories where parentID = #val(attributes.parentID)# </cfquery>
<!--- now display them ---> <cfoutput query="qGetCategories"> <a href="#categoryID#">#category#</a><br /> <!--- now here call this tag again, this time with this categoryID ---> <cf_categories parentID="#categoryID#" /> </cfoutput>
</cfif>
Now on your main page (where you want to show them) you simply do an initial call:
<cf_categories parentID="0" />
Since the first call is provided with a "0" it will load the parent ones... then as you begin to loop through; it will call itself in as many times as there are child categories... So you can go as many levels as you want.
If you only want to go two levels; then you can do something like this:
<!--- now display them ---> <cfoutput query="qGetCategories"> <a href="#categoryID#">#category#</a><br /> <!--- now here call this tag again, this time with this categoryID ---> <cfif attributes.parentID eq 0> <cf_categories parentID="#categoryID#" /> </cfif> </cfoutput>
That will only loads the first level of children... hope this helps... let me know if you have questions!
P
Pablo Varando Senior Application Architect EasyCFM.COM, LLC.