Connecting Tech Pros Worldwide Forums | Help | Site Map

breadcrumb based navigation

Justino
Guest
 
Posts: n/a
#1: Nov 3 '08
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;
?>

Jerry Stuckle
Guest
 
Posts: n/a
#2: Nov 3 '08

re: breadcrumb based navigation


Justino wrote:
Quote:
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;
?>
>
Try comp.databases.mysql for mysql questions. It all depends on your
database setup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Captain Paralytic
Guest
 
Posts: n/a
#3: Nov 3 '08

re: breadcrumb based navigation


On 3 Nov, 04:40, Justino <gerb...@gmail.comwrote:
Quote:
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=appleswill 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.
>
The very next page tells you the better way!
http://www.sitepoint.com/article/hie...ta-database/2/
Justino
Guest
 
Posts: n/a
#4: Nov 3 '08

re: breadcrumb based navigation


On Nov 3, 5:25*am, Captain Paralytic <paul_laut...@yahoo.comwrote:
Quote:
On 3 Nov, 04:40, Justino <gerb...@gmail.comwrote:Hi, *I'm trying tointegrate breadcrumb based navigation on my site,
Quote:
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=appleswilloutput 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.
>
Quote:
I used the ‘adjacency list model' here:http://www.sitepoint.com/article/hie...data-database/
>
Quote:
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.
>
The very next page tells you the better way!http://www.sitepoint.com/article/hie...ta-database/2/
I went with the adjacency list model because my tree is not big at
all. It seems to be fine with small data trees. It's when you use
large sets of data that it gets slow. Also, this method looked a lot
easier for a n00b like me. Thanks.
Closed Thread


Similar PHP bytes