title: Problem with putting Category "parent" and Subcategory ''child'' into a table
body: <p>I tried to print an array of a parent child tree. The code I used does not seem to print anything.</p>
  <pre><code>&lt;?php
  $sql = &quot;
  
  SELECT *,
         category_name parent_category_name,
         '' path
  FROM categories
  LEFT JOIN categories ON parent_id = id
  ORDER BY parent_id, id
  
  &quot;;
  
  function print_row ( $rowdata )
  {
  ?&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            &lt;?=$rowdata['id']?&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;?=$rowdata['path']?&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;?=$rowdata['type']?&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;?=$rowdata['status']?&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
  &lt;?php
  
  }
  
  $stmt  = $dbh-&gt;prepare($sql);
  $stmt-&gt;execute();
  $result = $stmt-&gt;get_result();
  $data = $result-&gt;fetch_all(MYSQLI_ASSOC);
  
  $printed = array();
  
  foreach ($data as $row)
  {
  
     if ( $row['parent_id'] == '' )
     {
        $row['path'] = $row['category_name'] . '/';
        $printed[$row['id']] = $row;
     }
     else
     {
        $row['path'] = $printed[$row['parent_id']]['path'] . $row['category_name'] . '/';
        $printed[$row['id']] = $row;
     }
  }
  
  
  array_multisort(array_column($printed, 'path'), SORT_ASC, $printed);
  
  foreach ( $printed as $prow )
  {
     print_row ( $prow );
  }
  ?&gt;
  &lt;/table&gt;
  </code></pre>
  <p>Mysql Categories</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>parent_id</th>
  <th>category_name</th>
  <th>category_description</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>0</td>
  <td>General</td>
  <td>desc</td>
  </tr>
  <tr>
  <td>2</td>
  <td>1</td>
  <td>Announcements</td>
  <td>desc</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The result that I want to create looks like this</p>
  <p><a href="https://i.stack.imgur.com/01FTe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/01FTe.png" alt="https://i.stack.imgur.com/01FTe.png" /></a></p>
  <p>Does anyone know how to fix this problem because the <code>&lt;?php ?&gt;</code> also causes other parts of HTML to disappear.</p>