breadcrumb based navigation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justino

    breadcrumb based navigation

    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($categ ory) {

    // look up the parent of this node

    $result = mysql_query('SE LECT parent_label FROM select_chain '.
    'WHERE label="'.$categ ory.'";');
    $row = mysql_fetch_arr ay($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=ge t_path($categor y);

    // print foreach array element

    foreach($breadc rumbs as $cat){
    print('<a href="mypage.ph p?category='.$c at .'">'.$cat . "</a ");
    }
    print $category;
    ?>
  • Jerry Stuckle

    #2
    Re: breadcrumb based navigation

    Justino wrote:
    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($categ ory) {
    >
    // look up the parent of this node
    >
    $result = mysql_query('SE LECT parent_label FROM select_chain '.
    'WHERE label="'.$categ ory.'";');
    $row = mysql_fetch_arr ay($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=ge t_path($categor y);
    >
    // print foreach array element
    >
    foreach($breadc rumbs as $cat){
    print('<a href="mypage.ph p?category='.$c at .'">'.$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@attgl obal.net
    =============== ===

    Comment

    • Captain Paralytic

      #3
      Re: breadcrumb based navigation

      On 3 Nov, 04:40, Justino <gerb...@gmail. comwrote:
      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!

      Comment

      • Justino

        #4
        Re: breadcrumb based navigation

        On Nov 3, 5:25 am, Captain Paralytic <paul_laut...@y ahoo.comwrote:
        On 3 Nov, 04:40, Justino <gerb...@gmail. comwrote:Hi,  I'm trying tointegrate 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=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.
        >
        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/
        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.

        Comment

        Working...