I am having some trouble going about working backwards in a query. I would like to make a type of breadcrumb trail, working back until parent = 0. My menu is set up in a database (navigation) with fields ID, Parent, Title, etc. My code looks like the below. Is there a way, after finding the ID and Parent of the page I'm on, working backwards dynamically until Parent = 0?
if(func_get_arg(3)) {
$id = func_get_arg(3);
$data = "id = '".$id."'";
} elseif ($scategory == '0') { //if no parent, switch what we look for
$data = "id = '".$category."' AND parent = '".$scategory."'";
} else {
$data = "id = '".$scategory."' AND parent = '".$category."'";
}
//echo $data;
$query = "select * from navigation WHERE ".$data." AND active='y' ORDER BY title";
//echo $query;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
if ($scategory == '0') { //if we not at a subcategory - display main header
echo '<img src="images/nav/heads/'.$row['image'].'" alt="'.$row['title'].'" border="0"><BR>';
} else { //if we are at a subcategory of a main heading, find parent of this and display parent graphic and subcategory text
$query = "select * from navigation WHERE ".$data." AND active='y' ORDER BY title";
$result = mysql_query($query);
$num_crumbs = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
if ($row['parent'] != 0) { // work back until parent equals 0
echo "Parent doesn't equal 0 yet.<BR>";
}
echo ">> ".$row['title'];
}
}
}