如何显示和正确缩进树结构[关闭]

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>

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;