title: Show categories and subcategories with 2 while statement
body: <p><a href="https://i.stack.imgur.com/uwP5S.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uwP5S.jpg" alt="enter image description here"></a></p>
  
  <p>I have a mysql table for categories and subcategories to order in a dropdown menu list. I thought to use a while statement into while, but i get only the first main category with relative subcategories and then the loop stop after the first record.</p>
  
  <p>How i want to display it:</p>
  
  <pre><code>-1 main cat  
     -1.1 sub-cat
     -1.2 sub-cat ...and so on
  
  -2 main cat
     - 2.1 sub-cat
     - 2.2 sub-cat...and so on
  </code></pre>
  
  <p>this is the simple test page:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;title&gt;Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;ul&gt;
  &lt;?php
  
      $main_cat = "SELECT * 
                  FROM category 
                  WHERE cat_parent_id = :value 
                  AND cat_lang = 'gb' 
                  ORDER BY cat_id ASC";
      $stmt = $con-&gt;prepare($main_cat);
      $stmt-&gt;bindValue(':value', 0, PDO::PARAM_STR);
      $stmt-&gt;execute();
      while ($row_main = $stmt-&gt;fetch(PDO::FETCH_ASSOC)){
          extract($row_main);   
   ?&gt;     
  &lt;li&gt;&lt;?php echo $cat_name; ?&gt;&lt;/li&gt;
    &lt;li&gt;
     &lt;ul&gt;
    &lt;?php
  
          $sub_cat = "SELECT * 
                      FROM category 
                      WHERE cat_parent_id = ?  
                      ORDER BY cat_id ASC";
          $stmt = $con-&gt;prepare($sub_cat);
          $stmt-&gt;bindParam(1, $cat_id);
          $stmt-&gt;execute();
          while ($row_sub = $stmt-&gt;fetch(PDO::FETCH_ASSOC)){
              extract($row_sub);   
   ?&gt;   
  
  &lt;li&gt;&lt;?php echo $cat_name; ?&gt;&lt;/li&gt;
  &lt;?php   }
      } 
  ?&gt;          
  
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>