title: Dynamically generate table using PHP
body: <p>I know this has been asked before and I have got it working using the following code:</p>
  
  <pre><code>&lt;?php
  $maxcols = 8;  $i = 0;
  echo "&lt;table id='table1'&gt;&lt;tr&gt;";
  
  foreach ($id as $k =&gt; $v) {
      echo "&lt;td id='0'&gt;&lt;div id='{$k}' class='drag t1'&gt;{$v}&lt;/div&gt;&lt;/td&gt;"; $i++;
      if ($i == $maxcols) { $i = 0; echo "&lt;/tr&gt;&lt;tr&gt;"; }
  } $i++;
  
  
  while ($i &lt;= $maxcols) {
      $i++; echo "&lt;td&gt;&lt;/td&gt;";
  }
  
  echo "&lt;/tr&gt;&lt;/table&gt;";
  ?&gt;
  </code></pre>
  
  <p>This results in a table that looks like this :</p>
  
  <p><img src="https://i.stack.imgur.com/O3OCq.jpg" alt="enter image description here"></p>
  
  <p>I'd like to add headers to this so the end result looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/Vpuvk.jpg" alt="enter image description here"></p>
  
  <p>I'd like to do it dynamically so if I create a table that is only 5 columns wide I'd get on the first header row ID01 - ID05 and on the second header row ID06 - ID10</p>
  
  <p>I want to limit the header ID values to be no more than <strong>$maxid</strong> any extra header fields should be blank, like this : If <strong>$maxid = 12;</strong> then :</p>
  
  <p><img src="https://i.stack.imgur.com/dSGOV.jpg" alt="enter image description here"></p>
  
  <p>I need the header rows are made as follows and not using <code>&lt;TH&gt;</code></p>
  
  <pre><code>&lt;td class="mark"&gt;
  </code></pre>
  
  <p>I'm using some javascript to allow the movement of cell data.    </p>
  
  <p>The class is used to set the formatting on the header and stop items from being dragged into the fields.</p>
  
  <p>Can anyone point me in the right direction on how to do this.</p>