title: Using foreach to display results
body: <p>I'm trying to write some sort of forum homepage, based off work someone else did. Here's what I've got so far:</p>
  
  <h1>Forums</h1>
  
  <pre><code>&lt;?php
   $crumbs = explode(",", $user['data']['depts']);
  
   foreach ($crumbs as &amp;$value) {
       $data = $db-&gt;query("SELECT * FROM tbl_depts WHERE id = '" . $value . "'");
       $crumb = $data-&gt;fetch_assoc();
       $data = $db-&gt;query("SELECT * FROM tbl_forums WHERE deptid = '" . $value . "'");
       $forumcount = $data-&gt;num_rows;
       $forum = $data-&gt;fetch_assoc();
  ?&gt;
  
  
  &lt;div class="h3top"&gt;&lt;?php echo $crumb['name']; ?&gt;&lt;/div&gt;
  &lt;div class="info2alt"&gt;
  &lt;?php
       while (($row = $data-&gt;fetch_array()) !== FALSE) {
           $forum[] = $row;
       }
  
       foreach ($forum as $row) {
  
           if ($forumcount &gt;= 1) {
               if ($forum['lastpost'] == "") {
                   $forum['lastpost'] = "--";
               }
  ?&gt;
              &lt;div class="info4"&gt;
                  &lt;table width="100%" border="0" cellspacing="1" cellpadding="4"&gt;
                      &lt;tr&gt;
                          &lt;td width="55%" align="left" valign="middle" class="zebraodd"&gt;&lt;a href="/forums/viewforum?id=&lt;?php echo $forum['fid']; ?&gt;"&gt;&lt;?php echo $row['name']; ?&gt;&lt;/a&gt;&lt;/td&gt;
                          &lt;td width="10%"&gt;Threads: &lt;?php echo $forum['threadcount']; ?&gt;&lt;br /&gt;Posts: &lt;?php echo $forum['postcount']; ?&gt;&lt;/td&gt;
                          &lt;td width="35%"&gt;Last Post: &lt;?php echo $forum['lastpost']; ?&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/div&gt;
  &lt;?php
   }
  ?&gt;
          &lt;?php if ($forumcount &gt;= 1) { ?&gt;
              &lt;div class="info3bottom"&gt;&lt;/div&gt;
  
              &lt;?php
          }
      }
      ?&gt;
  &lt;/div&gt;
  &lt;?php
   }
  ?&gt;
  </code></pre>
  
  <p>This is the current data in the table:</p>
  
  <p><img src="https://i.stack.imgur.com/X97Xe.png" alt="Table Data"></p>
  
  <p>Now, when I try to use this code, I get this:<img src="https://i.stack.imgur.com/F6T78.png" alt="Issue">, such that the first one is shown so many times, however, the next one does not appear. </p>
  
  <p>How do I fix this?</p>