I used to have a function that did exactly what I just described, but I threw it out when I decided to go with a flatter discussion model supported by potentially nested folders.
But you might find the following useful. It is a recursive function that assembles (does not print out, but builds) a string that serves as a bread crumb trail. It basically does the reverse of what I described, starting at the leaf and backing up to the root.
You call it like so:
echo breadcrumbs($location);
... where $location would be the unique ID of the current context (discussion that is being displayed). See this at the top of the pages at http://stonemountain.yi.org/.
In this example a "room" can be a discussion (a collection of notes arranged in a linear fashion) or a folder (a collection of discussions and/or folders).
function breadcrumbs($id)
{
global $roomid; // where we are
global $db; // db handle
global $prattle_rooms; // table name
global $breadcrumbtrail;
$result = mysql_db_query($db, "select * from $prattle_rooms where
roomid='$id'");
$room = mysql_fetch_object($result);
// if we are examining the CURRENT room, we
// don't print out a link, just the room name.
if ($id == $roomid)
$breadcrumbtrail = $room->title;
// otherwise, we want the room name to
// be clickable to "back up" to a higher level
else
$breadcrumbtrail = "<a href=\"prattle.php?roomid=$room->roomid\">$room->title</a> > $breadcrumbtrail";
// if we are not at the top level, look up and
// recurse ...
if ($room->roomparent) breadcrumbs($room->roomparent);
// return a printable string
return $breadcrumbtrail;
}