Hi!
I'm making website using php/mysql, however I am having problem with the breadcrumb navigation(EX: Home >section 1>section2...ect), I am not sure what would be the best way to make it considering my site structure.
so here's some info about my site structure:
I have a few section on my site: music, band, articles ect..all of these sections have subsection (EX: Music > Lyrics) and all of the subsections have their own subsections (EX:Music > Lyrics > With or Withour You).

EX (music section):
somesite.com/music/index.php (music section index page, this page is not in connection with database, just a simple php + text).
somesite.com/music/lyrics/index.php(subsection of music page that grabs song titles from database and returns list of songs in alphabetical order).
somesite.com/music/lyrics/song.php?id=210(this is a subsection of lyrics it's a dynamic page, which grabs song lyrics from DB..).

So can you suggest me what would be a best solution for me?

Any help would be appreciated!

Thanks

    Mordecai
    thx.
    but that seems to complicated for me.:rolleyes:

      No, it's not complicated at all... Basically, just check the parent of whichever node you're in, then check the parent of that node, if it's not the root node. Rinse and repeat.

        aha i've got that.

        |id|-------|name|--------------|parent|
        1-------category 1----------------0
        2-------subcategory 1-----------1
        3-------subcategory 2-----------1
        4-------subcategory 3-----------2

        that means that:
        Category 1> subcategory 1;
        Category 1>subcategory 2;
        Category 1 >subcategory 1> subcategory 3;

        somethin' like this right?
        but php part of this navigation is still unclear to me, like how script will guess which section is viewed by the user...ect...can you point me to lil' example of this script?

        thank you for the response!

          A little recursion and you're on your way

          <?php
          function bread_crumb($id) {
              $sql = "SELECT * FROM <category> WHERE id = $id";
              $query = mysql_query($sql);
              if($query) {
                  $row = mysql_fetch_assoc($query);
                  if($row['parent'] == 0)
                      return '<a href="' . $row['link'] . '">' . $row['name'] . '</a>';
                  else
                      return bread_crumb($row['parent']) . ' > ' . '<a href="' . $row['link'] . '">' . $row['name'] . '</a>';
              } //end if
              return FALSE;
          } //end break_crumb

            drawmack
            thx for the code. 🙂

            $sql = "SELECT * FROM <category> WHERE id = $id";

            ok if i'm not mistaken it gets current page ID(probably through url: some.php?id=1) and returns it's name from database, right?
            but what if i want breadcrumbs to appear on non-dynamic pages like /some directory/test.php?

            thx again! 🙂

            any ideas?

              Two things:
              1) a static page can still be linked to from the database and would then have an id in the database.

              2) if you really want to do this without interacting with the database then it would have to be done via the path like this.

              <?php
              $path = $_SERVER['PHP_SELF'];
              $path_ary = explode('/',$path);
              $temp_path = '';
              for($i=0;$i<(count($path) - 1);$i++) {
                  $temp_path .= $path[$i] . '/';
                  echo '<a href="http://www.mydomain.com' . $temp_path . '>' . ucfirst($path[$i]) . '</a> &gt; ';
              } //end for
              ?>

              NOTE: I HAVE NOT TESTED OR DEBUGGED THIS CODE

                a static page can still be linked to from the database and would then have an id in the database.

                can you explain how to achive this?:rolleyes:
                plus i've got lyrics table with over 200 lyrics in it. should I enter all song names in "breadcrumb" table?
                EX:
                id----name--------------------------parent
                1----lyrics-----------------------------0
                2 ---Were In this together--------1

                thanks!

                  Originally posted by theperfectdrug
                  can you explain how to achive this?:

                  menu
                      id
                      name
                      parent_id
                      file_name
                  

                  it's not that hard to figure out.

                  plus i've got lyrics table with over 200 lyrics in it. should I enter all song names in "breadcrumb" table?

                  no you should write a script that updates the breadcrumb table from the lyrics table
                  :rolleyes:

                    drawmack 100 thx.
                    so in file_name field i'll enter somethink like: test.php right?
                    and how script will get the ID of current section if url stays static(EX: /some dir/test.php)?😕

                      Write a Reply...