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 6211655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:22:37+00:00 2026-05-24T06:22:37+00:00

PHP newbie here. I’m currently developing a shopping cart web site using PHP and

  • 0

PHP newbie here. I’m currently developing a shopping cart web site using PHP and my question is how do I make a dynamic category tree listing on my side bar? Because I have no idea on how to implement it. I’m done with adding of categories in database.

  • 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-24T06:22:37+00:00Added an answer on May 24, 2026 at 6:22 am

    With the limited information you provided on how many levels of categories you require, here is an example that may help?

        // create a function to get the categories
        function getCategories() {
            // query the top level categories
            $query = "SELECT catId,catName FROM categories ORDER BY catName";
            $result = mysql_query($query);
            // check that you got some results before proceeding
            if (mysql_num_rows($result)>0) {
                // create a $html variable to return from the function
                $html = '<ul class="L1-categories">';
                // loop through the results
                while ($rows = mysql_fetch_object($result)) {
                    // append top level cats to your $html variable
                    $html .= '<li><a href="index.php?category='.$rows->catId.'">'.$rows->catName.'</a>';
                    // repeat the above query for 2nd level categories (sub cats)
                    $queryL2 = "SELECT subId,subName FROM subCategories WHERE catId=".$rows->catId." ORDER BY subName";
                    $resultL2 = mysql_query($queryL2);
                    // check you got results
                    if (mysql_num_rows($resultL2)>0) {
                        // continue appending the variable with some html that show sub cats indented
                        $html .= '<ul class="L2-categories">';
                        // loop through the sub cats
                        while ($rowsL2 = mysql_fetch_object($resultL2)) {
                            // if there were sub sub cats etc you just keep this code going deeper
                            $html .= '<li><a href="index.php?category='.$rows->catId.'&sub='.$rowsL2->subId.'">'.$rowsL2->subName.'</a></li>';
                        } // end sub cats loop
                        $html .= '</ul>';
                    } // end check for results
                    $html .= '</li>';
                } // end top level cats loop
                $html .= '</ul>';
            }
            return $html;
        }
    
        // usage
        echo getCategories();
    

    Style up your L1-categories and L2-categories in your css file as required for your side bar and you should be on your way, those links will need to change to suit your website they are just there for an example

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

Sidebar

Related Questions

Newbie question here: I'm using ANSI C on server to crunch numbers for a
PHP/MySQL newbie here. I managed to develop a web page that displays info from
Newbie question here, is there any inbuilt PHP tag that can be used to
Please, I'm a newbie in PHP, and created my web site, with a text
Quick newbie question here, how do I access totalResults ? XML <?xml version=1.0 encoding=UTF-8?>
On a PHP site using the smarty template engine (or at least a close
Am Newbie here.Am Beginner in php.I Create a sample Reg form.Here i want to
Just starting with php and sorry if this is a newbie question but i'm
A newbie here: sorry if the question is too simple, been looking in tutorials
Total newbie here, so take it as you will... I'm doing a site upgrade

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.