如何使用CSS在PHP中使用if语句更改背景颜色

I'm looking to change the color of a cell in a table based on returns from a mySQL database.

song_order |   encore    
1          |     0             
2          |     0       
3          |     0       
4          |     0       
5          |     0       
6          |     0      
7          |     0       
8          |     1      
9          |     1       
10         |     1        
11         |     2       
12         |     2     

I'm echoing out the song_id cell but not the encore cell... How can I use the values in the encore cell to change the background of the song_id cell only?

 while($row = mysqli_fetch_array($show))
  {   

  echo "<tr>";  

   echo "<td style='padding: 10px; width:5px;'>" . $row['song_order'] ." </td>";
  echo "</tr>";
  }
  echo "</table>";

Would it be something like this? But how do I add these if values to 'song order'? I just don't know if this is right or how it needs to be modified...

while($row = mysqli_fetch_array($show))

{if ($row['encore'] == "0") $tdClass = 'mainset';

else if ($row['encore'] == "1") $tdClass = 'encore1';

else if ($row['encore'] == "2") $tdClass = 'encore2';

echo "";

echo "" . $row['song_order'] ." "; } echo "";

CSS
 .mainset {
    background-color:transparent;
 }
 .encore1 {
    background-color:pink;
 }
 .encore2 {
    background-color:blue;
 }

Am I on the right track, can someone help me with this code? Am I missing something and this already works?

Now put the class like

echo "<tr>";  
    echo "<td style='padding: 10px; width:5px;' class='<?php echo $tdClass;?>'>" . $row['song_order'] ." </td>";
 echo "</tr>";

And makesure that you put the right classes for the right css

As per you comment try like this.Yor are echoing $tdClass in an echo which causes you conflict

 while($row = mysqli_fetch_array($show)) {
     if ($row['encore'] == "0") 
         $tdClass = 'mainset'; 
     else if ($row['encore'] == "1") 
         $tdClass = 'encore1'; 
     else if ($row['encore'] == "2") 
          $tdClass = 'encore2'; 
     echo "<tr>"; 
         echo "<td style='padding: 10px; width:5px;' class='".$tdClass."'>" . $row['song_order'] ." </td>";
     echo "</tr>";
}

css classes or ids can't start with numbers

change:

.1encore {
    background-color:pink;
 }
 .2encore {
    background-color:blue;
 }

to

 .encore1 {
    background-color:pink;
 }
 .encore2 {
    background-color:blue;
 }