title: foreach codeigniter count index for generate result() into html table
body: <p>I have a result() based active record codeigniter.
  In result is have 28 record
  I meant to create a table based this record.
  My question is, I want to make 7 row, and 4 column for more readable.
  My code is like this:</p>
  
  <pre><code>&lt;td colspan="4"&gt;
     &lt;?php
          foreach ($damage_codes as $row) {
              // Create a column. &lt;td&gt;
              // create a row &lt;tr&gt;
              // When this column have four row, create a next column  again.
              // So on, so on 
  
                echo  . $row-&gt;DAMAGE_ID . " " . $row-&gt;NAMA_DAMAGE ;
          }
          ?&gt;
      &lt;/td&gt;
  </code></pre>
  
  <p>I have to manage it, but not suitable with my own report.
  This is my code right now</p>
  
  <pre><code>&lt;?php 
      $i = 0;
      foreach ($damage_codes as $row) : ?&gt;
          &lt;?= ($i % 4 == 0) ? "&lt;tr&gt;" : false; ?&gt;
          &lt;?= "&lt;td&gt;[".$row-&gt;DAMAGE_ID . "]" . $row-&gt;NAMA_DAMAGE . "&lt;/td&gt;"; ?&gt;
  
      &lt;?php 
      $i++;
      endforeach;
      echo "&lt;/tr&gt;"?&gt;
  </code></pre>
  
  <p>and the output like this :</p>
  
  <pre><code>| 1  | 2  | 3  | 4  |
  | 5  | 6  | 7  | 8  |
  | 9  | 10 | 11 | 12 |
  | 13 | 14 | 15 | 16 |
  </code></pre>
  
  <p>How,can I make it like this :</p>
  
  <pre><code>| 1  | 5  | 9  | 13  |
  | 2  | 6  | 10 | 14  |
  | 3  | 7  | 11 | 15 |
  | 4  | 8  | 12 | 16 |
  </code></pre>
  
  <p>Any help it so appreciated</p>