title: Displaying forum categories with forums
body: <p>I want to display a list of categories with their corresponding forums, like every classic forum. <a href="http://punbb.informer.com/forums/" rel="nofollow">Heres an example</a>.</p>
  
  <p>I found this piece of code on the internet, it kinda works but it doesnt close tables properly. Every category should have their own table, right now it only closes with one <code>&lt;/table&gt;</code></p>
  
  <pre><code>// Start the table here - outside the loop
  echo '&lt;table&gt;'; 
  
  // Here's how you track if you need the header
  $lastCatID = -1;
  
  // Now loop
  foreach($query as $row)   
  {     
  // Only show cat header on condition
  if ($lastCatID &lt;&gt; $row['cid']) {
      echo '
        &lt;tr&gt;  
          &lt;th&gt;' . $row['cat_name'] . '&lt;/th&gt;
          &lt;th&gt;Latest Reply&lt;/th&gt;
          &lt;th&gt;Topics&lt;/th&gt; 
          &lt;th&gt;Posts&lt;/th&gt; 
          &lt;/tr&gt;';
  
      // Note that you've shows this header so you don't show it again.
      $lastCatID = $row['cid'];
  }
  
  
  // Now output the rest       
  echo '&lt;tr&gt;';  
  echo '&lt;td width="55%"&gt;Link&lt;/a&gt;&lt;/td&gt;';
  echo '&lt;td width="25%"&gt;User&lt;/td&gt;';
  echo '&lt;td width="10%" align="center"&gt;23523&lt;/td&gt;';
  echo '&lt;td width="10%" align="center"&gt;343235&lt;/td&gt;';
  echo '&lt;/tr&gt;';
  
  }
  
  echo '&lt;/table&gt;';
  </code></pre>