title: Alternating between even and odd in a while loop in PHP
body: <p>I have been working on couple of lines of code but I can't seem to get it to work. Basically I want to alternate between even and odd table-styles via a while loop. What am I doing wrong?</p>
  <p>Seems as though it only loops through the if() everytime.</p>
  <p>Thanx!</p>
  <pre><code>&lt;?php
      include 'connect.php';
      echo &quot;&lt;table id='hor-zebra'&gt;&quot;;
      $i = 0;
      while($row = mysql_fetch_array($result))
      {
         if(i%2 == 0)
         {
            echo &quot;&lt;tr class='even'&gt;&quot;;
            echo &quot;&lt;td&gt;&quot; . $row['departure'] .&quot; ✈ &quot;. $row['destination'] . &quot;&lt;/td&gt;&quot;;
            echo &quot;&lt;/tr&gt;&quot;;
         }
         
         else
         {
            echo &quot;&lt;tr&gt;&quot;;
            echo &quot;&lt;td&gt;&quot; . $row['departure'] .&quot; ✈ &quot;. $row['destination'] . &quot;&lt;/td&gt;&quot;;
            echo &quot;&lt;/tr&gt;&quot;;
         }
         $i++;
      }
      echo &quot;&lt;/table&gt;&quot;;
  
      mysql_close($con);
  
    ?&gt;
  </code></pre>