title: Traverse a DAG (Directed Acyclic Graph) from specified node to create a tree view
body: <p>I am putting together a parts database using the method below for directed acyclic graphs.
  <a href="http://www.codeproject.com/Articles/22824/A-Model-to-Represent-Directed-Acyclic-Graphs-DAG-o" rel="nofollow">http://www.codeproject.com/Articles/22824/A-Model-to-Represent-Directed-Acyclic-Graphs-DAG-o</a></p>
  
  <p>I am able to build my data set using the SQL queries from that page which I have converted to MySQL.</p>
  
  <p>Previously I have used the nested sets model although we found that deletions became a problem.
  I am unable to find any information on how to traverse the tree using this model. I simply need to be able to create a html tree to show the descendants from a selected parent node and identify leaf nodes (will be using jstree).</p>
  
  <p>I can post the code from the nested sets model if that helps. I don't need any help with the html it is the SQL I am stuck with.</p>
  
  <p>Does anyone have any idea where I can find information on the query I need.</p>
  
  <p>EDIT: 
  Following on from the commments I'd like to adapt to something more closely linked to Bill Karwins closure model. <a href="http://www.slideshare.net/billkarwin/models-for-hierarchical-data" rel="nofollow">http://www.slideshare.net/billkarwin/models-for-hierarchical-data</a>
  I notice however that on slides 49-50 which is where I want to select the descendants of a node that the output doesn't seem to provide enough to draw a simple tree. Previously with the nested sets model I was able to get a similar output that would traverse left to right, top to bottom. I'll try to explain.</p>
  
  <pre><code>Item | Depth
  
  1    |   0
  
  2    |   0
  
  3    |   1
  
  6    |   2
  
  7    |   0
  
  9    |   1
  </code></pre>
  
  <p>This allowed me to draw a tree as the SQL listed the order of descendants in a more manipulatable way. I believe it created "depth" by using a COUNT of subtrees and I will dig out the query if it would be useful here.</p>
  
  <p>Thanks again for all your help.</p>