breadcrumb based navigation

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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. 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 theadjacency list model' here: /=

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:


    $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=3D"'.$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']!=3D'') {

// the last part of the path to $category, is the name
// of the parent of $category

       $path[]=3D $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


// print foreach array element

    foreach($breadcrumbs as $cat){
    print('<a href=3D"mypage.php?category=3D'.$cat .'">'.$cat . "</a> > ");
    print $category;

Re: breadcrumb based navigation

Justino wrote:
Quoted text here. Click to load it

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.

Re: breadcrumb based navigation

Quoted text here. Click to load it
The very next page tells you the better way! /

Re: breadcrumb based navigation

Quoted text here. Click to load it

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.

Site Timeline