title: How do I visualize a MySQL Nested Set?
body: <p>I'm following the nested set model as represented here: <a href="http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/" rel="nofollow">http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/</a></p>
  
  <p>I have hierarchical data, effectively, a bunch of different graphs with edges/nodes, and am looking to visualize it. I understand the concept of the nested set, but am not sure how I know the parent/child relationships of each node without running an excessive amount of queries (performance).</p>
  
  <p>I'm attempting to use something like <a href="http://visjs.org/examples/network/basicUsage.html" rel="nofollow">http://visjs.org/examples/network/basicUsage.html</a> from visjs to create the graph.</p>
  
  <p>But visjs wants the data sets in the following formats:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    // create an array with nodes
    var nodes = new vis.DataSet([
      {id: 1, label: 'Node 1'},
      {id: 2, label: 'Node 2'},
      {id: 3, label: 'Node 3'},
      {id: 4, label: 'Node 4'},
      {id: 5, label: 'Node 5'}
    ]);
  
    // create an array with edges
    var edges = new vis.DataSet([
      {from: 1, to: 3},
      {from: 1, to: 2},
      {from: 2, to: 4},
      {from: 2, to: 5}
    ]);
  
    // create a network
    var container = document.getElementById('mynetwork');
    var data = {
      nodes: nodes,
      edges: edges
    };
    var options = {};
    var network = new vis.Network(container, data, options);
  &lt;/script&gt;
  </code></pre>
  
  <p>Is there a way I can run a single query or an efficient function that will return the data so that I know:</p>
  
  <p>Node 1 (lft 1, rgt 8) has childs Node 2 (2,3) and Node 3 (4,7)</p>
  
  <p>Node 3 has child Node 4 (5,6)</p>
  
  <pre><code>    Node 1
        /\
  Node 2  Node 3
            | 
          Node 4
  </code></pre>
  
  <p>I can get the full tree, or I can do the indented thing, </p>
  
  <p>Based on the visjs example, I am unsure how to efficiently know each node and its edges.</p>
  
  <p>Any advice would be greatly appreciated. Thank you!</p>