title: Creating number of table cells based on variable
body: <p>I am trying to display some images and radio buttons in a two-column table format.</p>
  
  <p>It should start a new row after every two images, instead, the row is ended even though the counter is less than 2 ($i == $c)</p>
  
  <p>I am getting:</p>
  
  <pre><code>&lt;td align="center" bgcolor=#CCCCCC&gt;
  &lt;img src=http://web.com/7534560_2.jpg width='200' height='125' /&gt;
  &lt;br&gt;Primary Image&lt;input type="radio" name="primary" id="primary"  
  value=http://web.com/7534560_2.jpg /&gt;
  **&lt;/td&gt;&lt;/tr&gt;**
  &lt;td align="center" bgcolor=#CCCCCC&gt;
  &lt;img src=http://web.com/7534560_3.jpg width='200' height='125' /&gt;
  &lt;br&gt;Primary Image&lt;input type="radio" name="primary" id="primary"  
  value=http://web.com/7534560_3.jpg /&gt;
  </code></pre>
  
  <p>Instead of the expected:</p>
  
  <pre><code>&lt;td align="center" bgcolor=#CCCCCC&gt;
  &lt;img src=http://web.com/7534560_2.jpg width='200' height='125' /&gt;
  &lt;br&gt;Primary Image&lt;input type="radio" name="primary" id="primary"  
  value=http://web.com/7534560_2.jpg /&gt;
  **&lt;/td&gt;**
  &lt;td align="center" bgcolor=#CCCCCC&gt;
  &lt;img src=http://web.com/7534560_3.jpg width='200' height='125' /&gt;
  &lt;br&gt;Primary Image&lt;input type="radio" name="primary" id="primary"  
  value=http://web.com/7534560_3.jpg /&gt;
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;?php 
  $iq = 2; // first image index offset
  $c  = '2'; // number of cells in a row
  $i  = 0;  // counter
  
  while ($image_qty + 1 &gt; $iq) {  
      if ($i==0) { 
          echo '&lt;tr&gt;'; 
      } 
  
      echo '&lt;td align="center" bgcolor=#CCCCCC&gt;';
      $image_url = substr($image_url, 0, -4); 
      $image_url = $image_url . "_$iq" . ".jpg";
      echo "&lt;img src=$image_url width='200' height='125' /&gt;&lt;br&gt;";
      echo 'Primary Image&lt;input type="radio" name="primary" id="primary" value=' . $image_url .' /&gt;';
      echo '&lt;/td&gt;'; 
  
      $image_url = $image_url_org; // reset image value
      $iq++; // increment image number
      $i++;  // increment cell counter
  
      if ($i == $c) // if number of cells at 2 end row 
      { 
          echo '&lt;/tr&gt;'; 
          $i = 0; 
      } 
  
      if ($i &gt; 0 ) // if cells remaining less than 2
      {
          echo '&lt;/tr&gt;'; 
      }
  }
  ?&gt;  
  </code></pre>