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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:42:45+00:00 2026-05-27T08:42:45+00:00

I am building a website for my college project and have decided to create

  • 0

I am building a website for my college project and have decided to create the front page. On it i have tried to display the menu by representing the parent categories and by dynamically populating the categories with their subcategories retrieved by recursively calling a function which does the same by fetching data from the database. However, the result only shows the main or parent menus and does not show the sub categories. I am at a loss.
The php code is shown below.

<?php
session_start();
include("connection.php");
$a=0;
if(isset($_SESSION["valid_user"]))
{
    echo "WELCOME ";
    echo $_SESSION["valid_user"];

    $name = $_SESSION["valid_user"];

    $sqllist   = "select * from category order by category_name";
    $rscatlist = mysql_query($sqllist);

    $catid1 = "";
    $opt    = "";

    while($rowcatlist = mysql_fetch_array($rscatlist))
    {
        $catid1  = $rowcatlist["category_id"];
        $catname = $rowcatlist["category_name"];
        $opt .= "<option value='$catid1'>$catname</option>";    
    }

    $sql1 = "select * from register where email_id='$name'" ;
    $rs1  = mysql_query($sql1);
    $row  = 0;
    $row1 = "";

    while($row1=mysql_fetch_array($rs1))
    {
        $row = $row1["admin"];
    }

    if($row==1)
    {
        echo "&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp<a href='admin/usermanagement/index.php'>Management Services </a> &nbsp ";
    }
    echo "<p align='right'><a href='logout.php'><font size='3'>logout</font></a></p>"."<br>" ."<br/>";
}
else
{
    echo "<p align='right'><a href='register.php'><font size='3'>Register</font></a> or <a href='login.php'><font size='3'>Login</font></a></p>"."<br/>"."<br/>";
}

$tbl = "";

$cat_id = 0;
$tbl = recursive($tbl,$cat_id);

function recursive($tbl,$cat_id)
{
    $sql = "select * from category where parent_id='$cat_id'";
    $rs  = mysql_query($sql);
    $tbl.="<ul>";
    while($row=mysql_fetch_array($rs))
    {
        $tbl .= "<li><a href='product.php?category_id=$row'[category_id]'>$row[category_name]</a>";
        $sql1 = "select * from category where parent_id=$row'[category_id]'";
        $rs1  = mysql_query($sql1);

        while($row1 = mysql_fetch_array($rs1))
        {  
            recursive($tbl,$row["category_id"]);
        }

        $tbl.="</li>";
    }  
    $tbl.="</ul>";
    return $tbl;
}


?>
  • 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-27T08:42:45+00:00Added an answer on May 27, 2026 at 8:42 am

    It seems odd that you’re calling the recursive() function right before you’re defining that function. It also seems odd that you’re only calling that function for the $cat_id of 0. Wouldn’t you need to loop through all your main-level category IDs and pass them into the function too?

    And good Lord, has anyone ever taught you to comment your code 😉

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

Sidebar

Related Questions

I am building a website templating system where multiple user can create their own
I am building a website to capture data. I have many spreadsheets that are
I am building a website using php and mysql.I have a login that is
I am just building website for our client. It is simple page which lists
Building a website using a PHP based Ecommerce product Magento. The problem I have
When building a website in Symfony 1.3 my development server refuses to display my
Am building a website which will have articles, policies and laws and text stuffs.
So I'm building a website in php codeigniter, and I have user submitted articles...
I'm building a website for my band and I have lots experience building websites
So I'm building a website that has a prices page in it that lists

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.