title: Creating four columns using php loop in table
body: <p>I am trying to make 4 column layout of table using php loop so it is conditional also. I am unable to create four columns as browser automatically inserts tr for tds without having trs. Maybe I am missing something...</p>
  
  <p>my code</p>
  
  <pre><code>&lt;?php $i=0; while($row = $result-&gt;fetch_assoc()){ ?&gt;
  &lt;?php if($i % 4){ echo "&lt;tr&gt;"; echo $i;} ?&gt;
  &lt;td&gt;&lt;?= $row['Zip_Code']?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="checkbox" name="zipcode[]" id="zip_&lt;?= $row['Zip_Code']?&gt;" value="&lt;?= $row['Zip_Code']?&gt;" &lt;?php echo (in_array($row['Zip_Code'], $zipcodes))? 'checked':'';?&gt; &gt;&lt;label class="zip_label" for="zip_&lt;?= $row['Zip_Code']?&gt;"&gt;&lt;/label&gt;&lt;/td&gt;
  &lt;?php if($i % 4){ echo "&lt;/tr&gt;"; } ?&gt;
  &lt;?php $i++; } ?&gt;
  </code></pre>
  
  <p>My Desired output </p>
  
  <pre><code>&lt;tr&gt;
  &lt;td&gt;blah &lt;/td&gt;
  &lt;td&gt;blah &lt;/td&gt;
  &lt;td&gt;blah &lt;/td&gt;
  &lt;td&gt;blah &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>but it shows me like this </p>
  
  <pre><code>&lt;tr&gt;
  &lt;td&gt;blah &lt;/td&gt;
  &lt;td&gt;blah &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>