title: Interrupt and return repetition within the while multiple times
body: <p>I'm not new here but I also do not ask questions because whenever I have a problem I find a solution in questions related here in the forum or in blogs, but I did not have any success with this problem.</p>
  
  <p>In a database I have the tables posts and categories that are related, and in a single MySQL query I am displaying the title of the posts within their categories. So far so good, everything working. However within the while loop structure the  tag with the is-sub class can not be repeated. Is there any way to stop the repetition of this while and then repeat it again?</p>
  
  <p>I thank you for your help</p>
  
  <pre><code>echo '
  &lt;nav class="navbar"&gt;
      &lt;ul&gt;';
  $sql = Query("SELECT * FROM posts INNER JOIN categories ON post_category = category_id ORDER BY post_category, post_title");
  
  $is_category = NULL; 
  
  while ($row = mysqli_fetch_assoc($sql)) :
  
      if ($row['post_category'] != $is_category) {
  
          echo '&lt;li class="has-sub"&gt;&lt;a href="#" class="opendown"&gt;' . $row['category_title'] . '&lt;/a&gt;';
  
          $is_category = $row['post_category'];
  
      }
          // stop loop
              echo '&lt;ul class="is-sub"&gt;';
                  // return loop
                  echo '&lt;li&gt;&lt;a href="?doc=' . $row['post_id'] . '"&gt;' . $row['post_title'] . '&lt;/a&gt;&lt;/li&gt;';
              // stop loop
              echo '&lt;/ul&gt;';
          // return loop
          echo '&lt;/li&gt;';
  
  endwhile;
  echo '
      &lt;/ul&gt;
  &lt;/nav&gt;';
  </code></pre>