title: PHP IF-statement to change color of table rows <td>?
body: <p>I have the following code written below. With this code I want to fetch data from MySQL database and print(echo) the result in table rows, each row with different colour. With this code data is fetched from database successfully but my condition for change color of rows is not working. Please check my code and let me know where I'm wrong. </p>
  
  <pre><code>&lt;table width="500" align="center" style="border:1px solid;"&gt;    
      &lt;?php 
          $query = "SELECT * FROM main_cat";
          $result = mysql_query($query);
          $count = mysql_num_rows($result);
          while($end = mysql_fetch_array($result)){
              echo "&lt;tr&gt;";
                  if($count % 2 == 0){
                      echo '&lt;td bgcolor="#CCCCCC"&gt;'.$end['page_name'].'&lt;/td&gt;';
                  }else{
                      echo '&lt;td bgcolor="#99CC66"&gt;'.$end['page_name'].'&lt;/td&gt;';
                  }
              echo "&lt;/tr&gt;";
              }
      ?&gt;
  &lt;/table&gt;
  </code></pre>