title: Foreach inside of While Loop Looks Funny
body: <p>I keep getting a wierd list after running this:</p>
  
  <pre><code>&lt;?php 
    $query_Category = "SELECT * FROM blog_categories ORDER BY category ASC";
  
    $getCategory = mysql_query($query_Category) or die(mysql_error()); 
  ?&gt;
  
  &lt;div id="sheader" style=""&gt;Categories&lt;/div&gt;
  
  &lt;div class="sbody" style="color:#000 !important;"&gt;
  
  &lt;?php 
     do { 
  ?&gt;
      &lt;div&gt;&lt;?php echo $row_getCategory['category'];?&gt;&lt;/div&gt;
  
  &lt;?php 
      $cat = $row_getCategory['cat_id'];
  
      $query_Subcategory = "SELECT * FROM blog_subcategories WHERE primcat_id = '$cat' ORDER BY subcategory ASC";
  
      $getSubCategory = mysql_query($query_Subcategory) or die(mysql_error());
      $row_getSubCategory = mysql_fetch_assoc($getSubCategory);
  
      $str = $row_getSubCategory['subcategory']; $subcategory = explode(',', $str);
  
      foreach ($subcategory as $arraysubcat) 
      {
         echo '&lt;div&gt;' . $arraysubcat . '&lt;/div&gt;';
      }
      } while ($row_getCategory = mysql_fetch_assoc($getCategory)); 
  ?&gt;
  
  &lt;/div&gt;
  &lt;?php mysql_free_result($getCategory); ?&gt;
  </code></pre>
  
  <p>I have a categories table with id &amp; category and a sub categories table with a id, subcategory, &amp; primary category id.
  I run it and it displays the foreach first randomly.</p>