title: PHP and mySQL table output row colors
body: <p>I have setup a mySQL database and am writing PHP code to read the contents of a table and output it as an HTML table. I want to alternate the row colors but I am struggling to do so. I have searched the topics here and tried everything I found but it's not working. Here is my code</p>
  
  <pre><code>&lt;?php
  
  {       //  Secure Connection Script
      include('../htconfig/dbConfig.php'); 
      $dbSuccess = false;
      $dbConnected = mysql_connect($db['hostname'],$db['username'],$db['password']);
  
      if ($dbConnected) {     
          $dbSelected = mysql_select_db($db['database'],$dbConnected);
          if ($dbSelected) {
              $dbSuccess = true;
          }   
      }
      //  END Secure Connection Script
  }
  
  if ($dbSuccess) {
  
  $query = "SELECT * FROM tvdbase"; 
  $result = mysql_query($query);
  
  echo "&lt;table&gt;"; 
  
  echo "&lt;table border='1'&gt;";
  
      echo "&lt;tr&gt;";
  
          echo "&lt;td&gt;Date&lt;/td&gt;";
          echo "&lt;td&gt;Course&lt;/td&gt;";
          echo "&lt;td&gt;Room&lt;/td&gt;";
  
      echo "&lt;/tr&gt;";
  
  $indx = 0;
  while($row = mysql_fetch_array($result)){
  $indx = $row['ID'];
  
  
      if ($indx % 2 == 0) {
          $bgColor = ' style="background-color:#CCFFFF;" ';
      } else {
          $bgColor = ' style="background-color:#FFFF99;" ';
      }
  
  echo "
  &lt;tr&gt;
  &lt;td bgColor&gt;" . $row['tvDate'] . "&lt;/td&gt;
  &lt;td bgColor&gt;" . $row['tvCourse'] . "&lt;/td&gt;
  &lt;td bgColor&gt;" . $row['tvRoom'] . "&lt;/td&gt;
  &lt;/tr&gt;"; 
  
  $indx++;
  
  }
  
  echo "&lt;/table&gt;";
  
  mysql_close();
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>It shows my table with the 3 columns (Date-Course-Room) but not the colors. </p>
  
  <p>Any help please?</p>