I need to find a simple solution to makeing breadcrumbs… not based on directories.
Let say I have a top category - Electronics (pass variables id in url)
the I get a list of sub categories under electronics - clicking on the sub-category (pass variables id in url)

I need to put the 1-Electronics in the breadcrumbs, once I click on something like Televisions, I view a list of sub-sub-categories, with 1-Electronics > 2-Televisions in the breadcrumbs… We all know how they work… the thing is, I need to pass in it the url to create the array or struct.

Electronics > Televisions > Flat Screens > Sony 60inch Plasma

got a sample sql for what you did?

I was doing something like this for a project i did. Unfortunately it was SUPER db intensive, but basically what I did was recursively find the parent based on parent_id column until parent_id was nil. Adding rows to the struct as it went along.

This idea might work since you’re only doing it once per page.

Of course you beat me to it Rudy. Was gonna post much the same thing.

running a query inside a loop is, to my way of thinking, inefficient

check out the (single) breadcrumb query here: Categories and Subcategories


<cfset breadcrumbs = ArrayNew()>
<cfset variables.target_id =>
<cfloop condition="my_query.parent_id EQ 0">
     <cfquery name="my_query" datasource="#APPLICATION.dsn#">
          SELECT id, parent_id, title
          FROM categories
          WHERE id = '#variables.target_id#';
     <cfset crumb_row = StructNew()>
     <cfset add_title = StructInsert(crumb_row, title, #my_query.title#)>
     <cfset add_id = StructInsert(crumb_row, id,>
     <cfset add_parent_id = StructInsert(crumb_row, parent_id, #my_query.parent_id#)>
     <cfset add_crumb = ArrayAppend(breadcrumbs, crumb_row)>
     <cfset variables.target_id = my_query.parent_id>

Don’t have access to the exact project code right now, but pretty sure it was something like so… I MAY have created a unordered list and dumped that to screen instead of a array of structs, but the general idea is present. Also, recursive was the wrong word to use for what I was/am suggesting. :slight_smile: