title: How change cell table color in php based on cell value?
body: <p>I just started programming in php. </p>
  
  <p>I made a table that returns values ​​from the database. 
  I'm trying to do the following: Change the color of the third column by the value it has.</p>
  
  <p>I was thinking this way, but the values ​​are repeated and the color is not the right way. </p>
  
  <p>Can anyone help me please? </p>
  
  <p>Did you understand my question? </p>
  
  <p>Thank you all. I apologize for the inconvenience.</p>
  
  <p>Code:</p>
  
  <pre><code>&lt;table style="width:324px;" border="3" cellspacing="1" cellpadding="1"&gt;
      &lt;tr&gt;
          &lt;td style="background-color:#A4A4A4;"&gt;
              &lt;b&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Task&lt;/font&gt;&lt;/b&gt;
          &lt;/td&gt;
          &lt;td style="background-color:#A4A4A4;"&gt;
              &lt;b&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;deadline&lt;/font&gt;&lt;/b&gt;
          &lt;/td&gt;
          &lt;td style="background-color:#A4A4A4;"&gt;
              &lt;b&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Status&lt;/font&gt;&lt;/b&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;?php
  $i=0;
  while ($i &lt; $num)
  {
      $f1=mysql_result($result,$i,"Task");
      $f2=mysql_result($result,$i,"deadline");
      $f3=mysql_result($result,$i,"status");
  
      ?&gt;
      &lt;tr style="background-color:#A4A4A4;"&gt;
          &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $f1; ?&gt;&lt;/font&gt;&lt;/td&gt;
          &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $f2; ?&gt;&lt;/font&gt;&lt;/td&gt;
          &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $f3; ?&gt;&lt;/font&gt;&lt;/td&gt;
          &lt;? 
          if($f3==2)
          { 
              // Display RED 
              ?&gt; 
              &lt;td style="background-color:#FF0;"&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $f3; ?&gt;&lt;/font&gt;&lt;/td&gt; 
              &lt;? 
          }
          elseif($f3==1)
          { 
              // Display YELLOW 
              ?&gt; 
              &lt;td style="background-color:#0F0;"&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $f3; ?&gt;&lt;/font&gt;&lt;/td&gt; 
              &lt;?     
          }
          else
          { 
              ?&gt; 
              &lt;td  style="background-color:#F00;"&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $f3; ?&gt;&lt;/font&gt;&lt;/td&gt; 
              &lt;? 
          } 
          ?&gt; 
      &lt;/tr&gt; 
      &lt;?php
      $i++;
  }
  ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Result from code:</p>
  
  <p><img src="https://i.stack.imgur.com/ToHt1.png" alt="enter image description here"></p>
  
  <p>SOLVED</p>
  
  <p>Thanks everyone for your help.
  Status is a predefined value recorded in the database. Only ranges between 1 and 4 so that the resolution has served @Daniel Andre correctly. 
  All responses were valid for me to try to understand a little more php, but it was so simple. 
  Again thank you all for your time and for your help. </p>
  
  <p>The final result was:</p>
  
  <pre><code>&lt;table style="width:324px;" border="3" cellspacing="1" cellpadding="1"&gt;
  &lt;tr&gt;
  
  &lt;td style="background-color:#A4A4A4;"&gt;
  &lt;b&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Tarefa&lt;/font&gt;&lt;/b&gt;
  &lt;/td&gt;
  &lt;td style="background-color:#A4A4A4;"&gt;
  &lt;b&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Prazo&lt;/font&gt;&lt;/b&gt;
  &lt;/td&gt;
  &lt;td style="background-color:#A4A4A4;"&gt;
  &lt;b&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Status&lt;/font&gt;&lt;/b&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;?php
  $i=0;while ($i &lt; $num) {
  $f1=mysql_result($result,$i,"idTarefa");
  $f2=mysql_result($result,$i,"PrazoExecucao");
  $f3=mysql_result($result,$i,"status");
  
  ?&gt;
  &lt;tr style="background-color:#A4A4A4;"&gt;
  &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $f1; ?&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $f2; ?&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;!--&lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $f3; ?&gt;&lt;/font&gt;&lt;/td&gt;--&gt;
  
  &lt;?php
    $status_colors = array(1 =&gt; '#0000FF', 2 =&gt; '#00FF00', 3 =&gt; '#FFFF00', 4 =&gt; '#FF0000');
  ?&gt;
  &lt;td style="background-color: &lt;?php echo $status_colors[$f3]; ?&gt;;"&gt;
  &lt;/tr&gt; 
  
  
  &lt;?php
  $i++;
  }
  ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/26rv4.png" alt="enter image description here"></p>