Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 474865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:19:51+00:00 2026-05-13T00:19:51+00:00

I want to create a guide bar (I don’t know its right name). I’ve

  • 0

I want to create a “guide bar” (I don’t know its right name). I’ve got a table called cat that has the following data:

catid        catname         parentid
1            news            null
2            sport           1
3            health          1
4            tennis          2
5            football        2
6            soccer          5

My page receives: $catid=6, and I want to create:

news>sport>football>soccer
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:19:52+00:00Added an answer on May 13, 2026 at 12:19 am

    First get your data from database and build an array

    $q = mysql_query("SELECT catid, catname, parentid FROM cat");
    $pages = array();
    while($r = mysql_fetch_assoc($q)) {
        $pages[$r['catid']] = array('catname' => $r['catname'], 'parentid' => $r['parentid']);
    }
    

    Use a recursive function to build the breadcrumbs:

    function build_breadcrumbs($pages, $catid) {
        if(is_null($catid) || empty($catid)) return;
        return build_breadcrumbs($pages, $pages[$catid]['parentid']).$pages[$catid]['catname'].' > ';
    }
    

    The function returns the parent’s breadcrumbs + the current breadcrumb. Use the function like this:

    $catid = 6;
    $breadcrumbs = trim(build_breadcrumbs($pages, $catid), ' >');
    echo $breadcrumbs;
    

    Or, if you like arrays more, you can create a function like this:

    function build_breadcrumbs($pages, $catid) {
        if(is_null($catid) || empty($catid)) return array();
        return array_merge(build_breadcrumbs($pages, $pages[$catid]['parent']), array($pages[$catid]['name']));
    }
    

    and use it with implode:

    $catid = 6;
    $breadcrumbs = implode(' > ', build_breadcrumbs($pages, $catid));
    echo $breadcrumbs;
    

    That gives you the option to define the separator outside the function. Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On each cell of my table view I want to have a bar that
How do I create a 9Patch image that only scales horizontally? I don't want
I want to create a client side mail creator web page. I know the
I want to create a function that performs a function passed by parameter on
I want to create a simple http proxy server that does some very basic
I want to create a tool in java that can be used to create
I want to create a ruby gem that calls a c function I have
Assuming I want to create an app that allows users to login. The accounts
I have Visual Studio 2005 Professional ENU installed and want to create GUIDs using
I want to be able to create a GUID/UUID on the iPhone and iPad.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.