Hello,
I have several navigation related functions which I would like to have no depth limits. These generate CSS menus, breadcrumb trails and the like.
I am stumped as to how I would make the functions follow each path to depth or to root without explicit looping.
The following is a typical example where I want the topmost parent of a page. The topmost will have a value of zero in its parent field.
Here is the explicitly looped version:
function topPg() {
$p = $this->retrieve("id = '$this->parent'");
if ($p->parent != 0) {
$gp = $this->retrieve("id = '$p->parent'");
if ($gp->parent != 0) {
$ggp = $this->retrieve("id = '$gp->parent'");
if ($ggp->parent != 0) {
$gggp = $this->retrieve("id = '$ggp->parent'");
// ad naseum
} else {
return $ggp;
}
} else {
return $gp;
}
} else {
return $p;
}
} // func
Anyone have advice or similar code or a tute link to help point the way?
TIA!!
jg