Skip to main content
Inspiring
March 16, 2010
Question

3 tier navigation

  • March 16, 2010
  • 1 reply
  • 501 views

Hi All,

I've been trying to get a multi level navigation working but am stumped. I want to display a 3 tier navigation, main_cat, sub_cat, sub_sub_cat.    

I have an access database with the tables inc main_cat, sub_cat, sub_sub_cat. My results so far are poor. I've been able to display all data but my best result is the sub_sub_cats appear under the last sub_cat:

Main_cat (top horizontal menu)

Sub_cat1

Sub_cat2

Sub_sub_cat1

Sub_sub_cat2

I would like Sub_sub_cat1 to appear under Sub_cat1, not under all sub_cats, demo page here (its a charity website I'm working on)

http://www.tbdev.cfdeveloper.co.uk/

My code so far:

query:


<CFQUERY NAME="GetSub_Cat_home" DATASOURCE="dsn">
SELECT id,Sub_Cat,Sub_Sub_Cat FROM data where main_cat = 'home'
</CFQUERY>

<CFQUERY NAME="GetSub_sub_Cat_home" DATASOURCE="dsn">
SELECT id,Sub_Cat,Sub_Sub_Cat FROM data where main_cat = 'home' and Sub_Sub_Cat = '#Sub_Sub_Cat#'
</CFQUERY>>

output:

<cfoutput query="GetSub_Cat_home">
     <li style="margin-left:10px"><a href="index.cfm?page=#page#&Sub_Sub_Cat=#Sub_Sub_Cat#">#sub_cat#</a></li>
        </cfoutput>
<cfif Sub_Sub_Cat EQ ""><cfelse>
         <cfoutput query="GetSub_sub_Cat_home">
             <a href="index.cfm?page=#page#&id=#id#&Sub_Sub_Cat=#Sub_Sub_Cat#&intro=no" style="margin-left:20px">#Sub_Sub_Cat#</a>
     </cfoutput>
</cfif>

    </ul>
</div>
</cfif>

Appreciate any help as I really need to get this done soon and am well stuck

Cheers

Trevor

This topic has been closed for replies.

1 reply

ilssac
Inspiring
March 16, 2010

Using seperate tables like that is a more complicated and limited way to do this type of thing.

The simple method that has worked well for me was a single table for all categories with a field that says category A is a subcategoy of B which is a subcetegory of C.

I.E.

CategoryParentCategory
A
BA
CB
DB

Then you can do a single simple query, order the results such at all the categories with the same parent is together.

Then problably a simple Group By output would display the results in a desired manner.  But with more complex displays in might requre a recurseive function.  I've used both from time to time.

Inspiring
March 16, 2010

I'd forgotten to update the database on the dev site, you will see my problem of positioning (currently only "home" setup) the sub_sub_cat under the appropriate sub_cat, hopefully your suggestion will help.

I'll go and have a play with that.

Cheers.

Trevor