Hi, I'm trying to integrate breadcrumb based navigation on my site,
but have hit a wall. I have an array that pulls from a MySQL data tree
(hierarchical) based on a variable passed in the url.
http://www.mysite.com?category=apples will output food fruit >
apples. I have everything working but instead of passing the string in
the url I'd rather pass the numerical id and use the string for
displaying only.
I used the ‘adjacency list model' here:
http://www.sitepoint.com/article/hie...data-database/
I'm not sure if this is the best way, but would it be possible to pass
the parent_id to the key of the array being used and how would I do
that? Any better ways? Thanks a ton for any help, Justin.
here's the code:
<?php
$category = $_GET["cat"]);
// $category is the name of the node we want the path of
function get_path($category) {
// look up the parent of this node
$result = mysql_query('SELECT parent_label FROM select_chain '.
'WHERE label="'.$category.'";');
$row = mysql_fetch_array($result);
// save the path in this array
$path = array();
// only continue if this $category isn't the root node
// (that's the node with no parent)
if ($row['parent_label']!='') {
// the last part of the path to $category, is the name
// of the parent of $category
$path[]= $row['parent_label'];
// we should add the path to the parent of this node
// to the path
$path = array_merge(get_path($row['parent_label']), $path);
}
// return the path
return $path;
}
//array goes into variable $breadscrumbs
$breadcrumbs=get_path($category);
// print foreach array element
foreach($breadcrumbs as $cat){
print('<a href="mypage.php?category='.$cat .'">'.$cat . "</a ");
}
print $category;
?>