title: Hierarchical data handling based on ID php mysql
body: <p>I have a sample MySQL table with the columns <strong>ID, NAME</strong> AND <strong>ID_PARENT</strong>.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>NAME</th>
  <th>ID_PARENT</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>NODE 1</td>
  <td>NULL</td>
  </tr>
  <tr>
  <td>2</td>
  <td>NODE 2</td>
  <td>1</td>
  </tr>
  <tr>
  <td>3</td>
  <td>NODE 3</td>
  <td>2</td>
  </tr>
  <tr>
  <td>4</td>
  <td>NODE 4</td>
  <td>2</td>
  </tr>
  <tr>
  <td>5</td>
  <td>NODE 5</td>
  <td>1</td>
  </tr>
  <tr>
  <td>6</td>
  <td>NODE 6</td>
  <td>5</td>
  </tr>
  <tr>
  <td>7</td>
  <td>NODE 7</td>
  <td>6</td>
  </tr>
  <tr>
  <td>8</td>
  <td>NODE 8</td>
  <td>7</td>
  </tr>
  <tr>
  <td>9</td>
  <td>NODE 9</td>
  <td>6</td>
  </tr>
  <tr>
  <td>10</td>
  <td>NODE 10</td>
  <td>5</td>
  </tr>
  <tr>
  <td>11</td>
  <td>NODE 11</td>
  <td>NULL</td>
  </tr>
  <tr>
  <td>12</td>
  <td>NODE 12</td>
  <td>11</td>
  </tr>
  <tr>
  <td>13</td>
  <td>NODE 13</td>
  <td>11</td>
  </tr>
  <tr>
  <td>14</td>
  <td>NODE 14</td>
  <td>13</td>
  </tr>
  <tr>
  <td>18</td>
  <td>NODE 15</td>
  <td>14</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>And I have the following tree based on the above data and I need to fetch a node/tree/hierarchy based on ID provided.</p>
  <pre><code>NODE 1
    NODE 2
      NODE 3
      NODE 4
    NODE 5
      NODE 6
        NODE 7
          NODE 8
        NODE 9
     NODE 10
  NODE 11
    NODE 12
    NODE 13
      NODE 14
        NODE 15
  </code></pre>
  <p>Now if I provide <strong>ID=6 (NODE 6)</strong> then we should have all the PARENTS (with their CHILDREN) of <strong>NODE 6</strong> plus all the nested CHILDREN of <strong>NODE 6</strong>. So, we should have <strong>NODES</strong> from <strong>1 to 10</strong> as they fall under one <strong>PARENT NODE 1</strong>. The extracted tree would be.</p>
  <pre><code>NODE 1
    NODE 2
      NODE 3
      NODE 4
    NODE 5
      NODE 6
        NODE 7
          NODE 8
        NODE 9
     NODE 10
  </code></pre>
  <p>So, how can we achieve the above-mentioned scenario?</p>
  <p><strong>NOTE: I am using PHP 7 and MySQL 5.6.</strong></p>