title: Split PHP loop into 2 lists
body: <p>I have built the following function, but is it possible to get it to split my lists from one into more so I can have a maximum of 8 <code>&lt;li&gt;</code>'s per <code>&lt;ul&gt;</code>?</p>
  
  <pre><code>function buildProductsMenu($base) {
  
      $sql = "SELECT *
              FROM tbl_category";
      $result     = dbQuery($sql);
      while ($row = dbFetchAssoc($result)) {
      echo "&lt;ul&gt;";        
          echo "&lt;li class='title'&gt;$row[cat_name]&lt;/li&gt;";
              $sqlProd = "SELECT *
                  FROM tbl_product WHERE cat_id = $row[cat_id]";
              $resultProd     = dbQuery($sqlProd);
              while ($rowProd = dbFetchAssoc($resultProd)) {
                  extract($rowProd);
                  echo "&lt;li&gt;&lt;a href='".$base."products/".strtolower($row['cat_name'])."/".strtolower($pd_name)."'&gt;".$pd_name."&lt;/a&gt;&lt;/li&gt;";
              }       
      echo "&lt;/ul&gt;";               
      }
  }
  </code></pre>
  
  <p><strong>Went with jurgemaister Solution</strong></p>
  
  <pre><code>function buildProductsMenu($base) {
  
      $sql = "SELECT *
              FROM tbl_category";
      $result     = dbQuery($sql);
      while ($row = dbFetchAssoc($result)) {
          echo "&lt;ul&gt;";        
          echo "&lt;li class='title'&gt;$row[cat_name]&lt;/li&gt;";
          $sqlProd = "SELECT * FROM tbl_product WHERE cat_id = $row[cat_id]";
          $resultProd     = dbQuery($sqlProd);
          $counter = 1;
          while ($rowProd = dbFetchAssoc($resultProd)) {
              extract($rowProd);
              if($counter % 12 == 0) {
                  $counter = 1;
                  echo "&lt;/ul&gt;&lt;ul style='margin-top:25px;'&gt;";
              }
              echo "&lt;li&gt;&lt;a href='".$base."products/".strtolower($row['cat_name'])."/".strtolower($pd_name)."'&gt;".$pd_name."&lt;/a&gt;&lt;/li&gt;";
              $counter++;
          }
          echo "&lt;/ul&gt;";
      }
  }
  </code></pre>