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

  • Home
  • SEARCH
  • 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 7893955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:16:09+00:00 2026-06-03T07:16:09+00:00

I have a database that looks like this: I can generate a tree from

  • 0

I have a database that looks like this:

enter image description here

I can generate a tree from this menu using the following code:

foreach($categories->result_array() as $category):
    $menu_array[$category['id']] = array('name' => $category['name'], 'parent' => $category['parent'], 'id' => $category['id']);
endforeach;

echo '<ul>';
echo $this->tasks->generateCategoriesTree(NULL, $menu_array);
echo '</ul>';

And here’s the function the above code calls:

function generateCategoriesTree($parent, $menu_array, $result = NULL)
{
    foreach($menu_array as $key => $value):
        if ($value['parent'] == $parent):
            $result .= '<li>';
            $result .= '<a href="#">' . $value['name'] . '</a>';
            $result .= '<ul>';
            $result .= $this->generateCategoriesTree($key, $menu_array);
            $result .= '</li></ul>';
          endif;
    endforeach;

    return $result;
}

It generates a tree that looks like this:

enter image description here

My problem now is getting the parent category to be bold. In my database, row’s that are parents have the parent column as NULL. I’ve tried a couple things, such as a if ($value['parent'] !== $parent) then applying a bold style, but that doesn’t work. I honestly cannot wrap my head around this. I would appreciate any help you guys can provide!

  • 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-06-03T07:16:11+00:00Added an answer on June 3, 2026 at 7:16 am

    I would make it bold if the parent is equal to NULL. I’m not sure about the use of the syntax since I normally use parentheses for if-structures.

    function generateCategoriesTree($parent, $menu_array, $result = NULL)
    {
        foreach($menu_array as $key => $value):
            if ($value['parent'] == $parent):
                $result .= '<li>';
                if($value['parent'] == NULL):
                    $result .= '<a class="BOLDCLASS" href="#">' . $value['name'] . '</a>';
                else:
                    $result .= '<a href="#">' . $value['name'] . '</a>';
                endif;  
                $result .= '<ul>';
                $result .= $this->generateCategoriesTree($key, $menu_array);
                $result .= '</li></ul>';
              endif;
        endforeach;
    
        return $result;
    }
    

    You would have to use some styling to make the class BOLDCLASS bold of course.

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

Sidebar

Related Questions

I have a mysql database that looks like this: |id | city | created
I have a table in a MSSQL database that looks like this: Timestamp (datetime)
I have a database that contains a table that looks a bit like this:
say i have a nvarchar field in my database that looks like this 1,
I have some code to update a database table that looks like try {
I have a database that look like this: [Invoice] -PK:ID -... [InvoiceDetail] -PK:ID -FK:Invoice_ID
I have many collections of documents in a mongo database that look like this:
I have a database full of text fields that look like this: (paragraph of
I have a string in my database that represents an image. It looks like
I'm using NHibernate 3.2 and I have a repository method that looks like: public

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.