title: How to display hierarchical "NESTED SET" data with PHP?
body: <p>I'm trying to figure out how to display nested MySQL data using php. I've managed to set aside all the "leaf nodes" but then I got stucked. I need to display a whole tree and all of it's element's relations. 
  Here's the table</p>
  
  <pre><code>category_id, name, lft, rgt
  1 Saws 1 12
  2 Chainsaws 2 7
  3 Red 3 4
  4 Yellow 5 6
  5 Circular saws 8 9
  6 Other saws 10 11
  </code></pre>
  
  <p>Here is code:</p>
  
  <pre><code>$query = 'SELECT node.name, node.lft, node.rgt
      FROM item_cats AS node,
          item_cats AS parent
      WHERE node.lft BETWEEN parent.lft AND parent.rgt AND parent.name = "' . SAWS . '"
      ORDER BY node.lft';
  $result = mysql_query($query, $db) or die (mysql_error($db));
  while ($row = mysql_fetch_assoc($result)) {
      if ($row['rgt'] == $row['lft']+1) {
          echo '==&gt;';
      }
      echo $row['lft'];
      echo $row['name'];
      echo $row['rgt'];
      echo '&lt;br /&gt;';
      echo '&lt;br /&gt;';
  }
  </code></pre>
  
  <p>And this is what i get:</p>
  
  <pre><code>1Saws12
  2Chainsaws7
  ==&gt;3Red4
  ==&gt;5Yellow6
  ==&gt;8Circular saws9
  ==&gt;10Other saws11
  </code></pre>