title: PHP count rows from foreach loop
body: <p>I'm using a "foreach" loop in PHP to create tables from my MySQL data</p>
  
  <p>What I'm trying to achieve is to count the amount of rows being returned by the loop</p>
  
  <p>The loop is creating new tables for each "machine" and fills the "contracts" as new rows but whenever I try to count the rows it returns the count from all tables together instead of only the a single one.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;?php
  
  foreach ($this-&gt;datatitle as $head) {
  
      $cards = 1;
  
      echo '&lt;table id="cards" class="cards"&gt;';
  
      echo '&lt;tr&gt;';
  
      foreach ($this-&gt;datacount as $datacount) {
  
          echo '&lt;td&gt;' . $head-&gt;machine_text . ' ' . $head-&gt;machine_name . ' [' . $datacount-&gt;count . ']&lt;/td&gt;';
  
      }
  
      echo '&lt;/tr&gt;';
      echo '&lt;tr&gt;';
      echo '&lt;td&gt;';
      echo '&lt;ul id="sortable" class="connectedSortable"&gt;';
  
      foreach ($this-&gt;data as $body) {
  
          if ($head-&gt;machine_text == $body-&gt;machine_text) {
  
              echo '&lt;li class="ui-state-default"&gt;Auftrag: ' . $body-&gt;aufnr;
              echo '&lt;br&gt;' . $body-&gt;matnr . ' ' . $body-&gt;matxt;
              echo '&lt;br&gt;Menge ' . $body-&gt;gamng;
              echo '&lt;br&gt;&lt;br&gt;';
              echo 'Start: ' . $body-&gt;gstrp;
              echo '&lt;br&gt;Ende: ' . $body-&gt;ssavd . '&lt;/li&gt;';
  
              if ($cards++ == 10) {
                  break;
              }
  
          } else {
  
          }
  
      }
  
      echo '&lt;/td&gt;';
      echo '&lt;/tr&gt;';
      echo '&lt;/table&gt;';
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>The $cards defines the amount of rows want to display, but i want to count the rows which aren't displayed aswell.</p>
  
  <p><strong>tl;dr</strong> create tables with foreach, want to count rows from single table</p>