Here is some code that I use. It does not print a bread crumb trail, but rather returns the complete trail as a string.
Note how it works:
It uses the specified $id to get the necessary data from the database.
It compares the current context ($roomid) to the specified $id. IF they match, THEN the string is set to the retrieved title (without a hypertext anchor); ELSE (no match) a linkset is constructed from the title and a URL mask and the result is prepended -- glued to the BEGINNING of the bread crumb trail.
If the parent id is not zero, the function calls itself with the parent ID as an argument.
This assumes that an object with a parent id of 0 is a root object.
Basically what we're doing here is building the bread crumb trail from right to left. When we're done, we will be able to print it (left to right, naturally):
echo breadcrumbs($roomid);
Here is the function definition:
function breadcrumbs($id)
{
global $roomid; // current context
global $db; // database handle
global $prattle_rooms; // table name
global $breadcrumbtrail; // string we build
$result = mysql_db_query($db, "select * from $prattle_rooms where
roomid='$id'");
$room = mysql_fetch_object($result);
if ($id == $roomid)
$breadcrumbtrail = $room->title;
else
$breadcrumbtrail = "<a href=\"prattle.php?roomid=$room->roomid\">$room->title</a> > $breadcrumbtrail";
if ($room->roomparent) breadcrumbs($room->roomparent);
return $breadcrumbtrail;
}