title: Even/Odd to determine CSS class
body: <p>I've read a lot of information about the determination of a even/odd number and using it to change the class of a div.</p>
  
  <p>In my case I want to switch the position of divs called MessagePicture and MessageText every new message posted.</p>
  
  <ol>
  <li>Picture left, Text right</li>
  <li>Picture right, Text left</li>
  <li>Picture left, Text right</li>
  <li>ect. </li>
  </ol>
  
  <p>This is the code I am using to display the messages, I also included one of my tries to get the even/odd code to work.</p>
  
  <p>Can anyone tell me what I should change to get it to work?</p>
  
  <pre><code>    &lt;?PHP
  
      $Query =
      "
              SELECT
                  ID,
                  NameBox,
              MessageBox,
              Code
          FROM
              messages
              ORDER BY
                  ID
              DESC LIMIT 10
      ";
  
      $Result = mysql_query($Query);
  
          if(!$Result)
              {
              echo 'ERROR: '.mysql_error();
              }
  
          else
              {
              if(mysql_num_rows($Result) == 0)
                  {
                      echo 'No results';
                  }
  
                  else
                      {
                      $i = 0;
                  $class = (++$i % 2) ? 'even' : 'odd';
                      while
                      ($Row = mysql_fetch_assoc($Result))
  
                          echo '
  
  &lt;div id="MessageWrapper"&gt;
      &lt;div id="MessagePicture" class="'.$class.'"&gt;                                                                                
          &lt;style&gt;                                             
          #MessagePicture { 
          background-image: url(../../../Images/'.stripslashes($Row['Code']).'.png);  
          background-repeat: no-repeat; 
          background-position: center
          &lt;/style&gt;
          &lt;/div&gt;
  
      &lt;div id="MessageText" class="'.$class.'"&gt;
  
          &lt;div id="MessageTitle"&gt;
  
              &lt;h1&gt;'.$Row['NameBox'].'&lt;/h1&gt;
  
          &lt;/div&gt;
  
          &lt;div id="MessageContent"&gt;                                                   
              &lt;p&gt;'.nl2br($Row['MessageBox']).'&lt;/p&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  
  &lt;/div&gt;  
  
  ';}}}?&gt;
  </code></pre>