How to display and properly indent a tree structure of a single node?
<p>The DB structure is as follows:</p>

<pre><code>    cat_ID| cat_name    | cat_nicename  | lft | rgt 
    _________________________________________________
    287   | Wallpapers  |  wallpapers   | 61  | 62
    1656  | Gadget      |  gadget       | 63  | 64
    1958  | Sms         |  sms          | 65  | 66
    2901  | fun         |  fun          | 67  | 68
    4419  | Joke        |  joke         | 69  | 70
    4775  | health      |  health       | 71  | 72
    5098  | Mobile      |  mobile       | 73  | 90
    5100  | TV          |  tv           | 91  | 92
    5101  | Main        |  main         | 93  | 94
    5102  | Nokia       |  nokia        | 76  | 83
    5103  | Samsung     |  samsung      | 84  | 87
    5104  | Micromax    |  micromax     | 88  | 89
    5105  | Nokia Sub 1 |  nokiasub1    | 77  | 78
    5106  | Nokia Sub 2 |  nokiasub2    | 79  | 82
    5107  | Nokia Sub 3 |  nokiasub3    | 80  | 81
    5109  | Galaxy      |  galaxy       | 85  | 86
</code></pre>

<p>The Folloing query I am using to get One category and all it's subcats:</p>

<pre><code>$sql = "SELECT n.cat_ID,n.cat_name,n.cat_nicename, (COUNT(*)-1)
 AS depth FROM " .TBL_CATEGORIES. " AS n, " .TBL_CATEGORIES. " AS p
  WHERE p.cat_nicename='mobile'
 AND n.lft BETWEEN p.lft AND p.rgt
 GROUP BY n.lft ORDER BY n.lft;";

$result = mysql_query($sql);

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

function _tab($depth) {
    $tabs = '';
    while ($depth-- &gt; 0) $tabs .= '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;';
    return $tabs;
}

// bootstrap loop
$result = '';
while (!empty($tree)) {
    $currNode = array_shift($tree);
    $result .= _tab($currNode['depth']) . $currNode['cat_name'] . $currNode['depth'].'&lt;br /&gt;';
}

print $result;
</code></pre>

<p>if i do not use <code>p.cat_nicename='mobile'</code>, by the above code, tree structure displays perfect, but if i want to retrieve just one node by using <code>p.cat_nicename='mobile'</code> All the depth I am getting is <code>'0'</code> hence it is NOT putting any <code>&amp;nbsp;</code> and displaying flat tree under <code>'mobile'</code>.. if i query just <code>"mobile"</code> it should display like:</p>

<pre><code>Mobile
    Nokia
        Nokia Sub 1
        Nokia Sub 2
            Nokia Sub 3
    Samsung
        Galaxy
    Micromax
</code></pre>

<p>so my questions are:</p>

<ol>
<li><strong>How can I display Tree of a particular node?</strong></li>
<li><strong>How can I display just all the root categories only? no childs no sub, by using single SQL query?</strong></li>
</ol>
