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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:56:23+00:00 2026-06-12T03:56:23+00:00

DB structure is this: INSERT INTO categories (title, lft, rgt) VALUES (‘Cat 1’,1,16); INSERT

  • 0

DB structure is this:

INSERT INTO categories (title, lft, rgt) VALUES ('Cat 1',1,16);
INSERT INTO categories (title, lft, rgt) VALUES ('Cat 2',2,3);
INSERT INTO categories (title, lft, rgt) VALUES ('Cat 3',4,7);
INSERT INTO categories (title, lft, rgt) VALUES ('Cat 4',5,6);
INSERT INTO categories (title, lft, rgt) VALUES ('Cat 5',8,13);
INSERT INTO categories (title, lft, rgt) VALUES ('Cat 6',9,12);
INSERT INTO categories (title, lft, rgt) VALUES ('Cat 7',10,11);
INSERT INTO categories (title, lft, rgt) VALUES ('Cat 8',14,15);  

When I run this query:

SELECT n.title, COUNT(*)-1 AS depth FROM categories AS n, categories AS p WHERE  n.lft BETWEEN p.lft AND p.rgt GROUP BY n.lft ORDER BY n.lft;

$result = mysql_query($query);

// Build array
$tree = array();
while ($row = mysql_fetch_assoc($result)) {
  $tree[] = $row;
}

After that I can use following function:

// bootstrap loop
    $result = '';
    $currDepth = -1;  // -1 to get the outer <ul>
    while (!empty($tree)) {
      $currNode = array_shift($tree);
      // Level down?
      if ($currNode['depth'] > $currDepth) {
        // Yes, open <ul>
        $result .= '<ul>';
      }
      // Level up?
      if ($currNode['depth'] < $currDepth) {
        // Yes, close n open <ul>
        $result .= str_repeat('</ul>', $currDepth - $currNode['depth']);
      }
      // Always add node
      $result .= '<li>' . $currNode['title'] . '</li>';
      // Adjust current depth
      $currDepth = $currNode['depth'];
      // Are we finished?
      if (empty($tree)) {
        // Yes, close n open <ul>
        $result .= str_repeat('</ul>', $currDepth + 1);
      }
    }

    print $result;

Can anyone tell me how to print above tree WITHOUT <ul> and <li>..
I want to print it using &nbsp; intended for child and sub-child… because I have to put it in <select> list and in other HTML tags

The structure I am using can be seen here: Getting a modified preorder tree traversal model (nested set) into a <ul>

  • 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-12T03:56:24+00:00Added an answer on June 12, 2026 at 3:56 am

    As an urgent response (and untested), because you already have the depth of each element/node, you could use that for how many &nbsp; blocks to output for each one, and then end each line with a <br /> (unless you need to separate elements by some other means).

    Try a function to output the spaces and it should be something as simple as this:

    function _tab($depth) {
        $tabs = '';
        while ($depth-- > 0) $tabs .= '&nbsp;&nbsp;&nbsp;&nbsp;';
        return $tabs;
    }
    
    // bootstrap loop
    $result = '';
    while (!empty($tree)) {
        $currNode = array_shift($tree);
        $result .= _tab($currNode['depth']) . $currNode['title'] . '<br />';
    }
    
    print $result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My query looks like this: INSERT INTO table1 (lfd, somedata) select (select max(lfd) +
This query appears in mysql slow query log: it takes 11 seconds. INSERT INTO
Table structure: title { name varchar(100) } If I try to insert a following
Ok: This is some of my table structure that matters here CaseStudyID int Title
I tried running the following statement: INSERT INTO VOUCHER (VOUCHER_NUMBER, BOOK_ID, DENOMINATION) SELECT (a.number,
Ok, when trying to insert into the database I'm getting this error You have
Perhaps this structure is not a good fit for Meteor, or maybe I'm thinking
I have this structure: Activity A has a ViewPager. The pages of a ViewPager
I approximatley this structure <div> <div id='1'> </div> <div id='2'> </div> </div> I want
I have this structure on form, <input type=test value= id=username /> <span class=input-value>John Smith</span>

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.