Change String color upon Mysql return

0

I have the code below, if the score column has a field with "LOW" the color of only the LOW has to be (# FFFF00) and if the field is HIGHT, only HIGHT must have the color (# FF0000):

   <?php  
    while($row = $stm->fetch())  {
    $color = $row["score"];

   echo "<tr>"."<td><input type=checkbox name='check[]' value='[]' ></td>"."</td><td>"."<font size='1'>" .$row['quantidade']. "</td><td>". "<font size='1'>". $row['data'] . "</td><td>"."<font size='1'>" . $row['ip'] . "</td><td>"."<font size='1'>" . $row['hostname'] . "</td><td>"."<font size='1'>" .$row['sender']. "</td><td>"."<font size='1'>" .$row['subject']."</td><td>"."<font size='1'>"."<div id=add9 align=middle style='color: {$color}; text-shadow: 1px 1px 1px black, 0 0 20px blue, 0 0 1px darkblue'>" .$row['score']. " <td><a href=delete.php?id=". $row['id'] . " data-placement='top' data-toggle='tooltip' title='Delete'><button class='btn btn-danger btn-xs' data-title='Delete' data-toggle='modal' data-target='#delete' </a><span class='glyphicon glyphicon-trash'></span></button></p>
</tr>".'' ;
}

  switch($color){

    case 'LOW':
        $color = "#FFFF00";
        break;
    case 'HIGH':
        $color = "#FF0000";
        break;  

        return $color;
}




 ?>

What happens that no color is changed in the field that has these cases. Could you help me where I'm wrong?

Thank you.

    
asked by anonymous 28.03.2017 / 19:51

1 answer

0

I was able to observe two possible problems:

Your Switch should be before your echo, try to create a function and call it inside the loop, below an example of how you can structure:

<?php  
function GetColor($color){
  switch($color){
    case 'LOW':
        $color = "#FFFF00";
        break;
    case 'HIGH':
        $color = "#FF0000";
        break;  
    }
    return $color;
}

while($row = $stm->fetch())  {
    $color = $row["score"];

   echo "<tr>"."<td><input type=checkbox name='check[]' value='[]' ></td>"."</td><td>"."<font size='1'>" .
   $row['quantidade']. "</td><td>". "<font size='1'>". 
   $row['data'] . "</td><td>"."<font size='1'>" . 
   $row['ip'] . "</td><td>"."<font size='1'>" . 
   $row['hostname'] . "</td><td>"."<font size='1'>" .
   $row['sender']. "</td><td>"."<font size='1'>" .
   $row['subject']."</td><td>"."<font size='1'>".
   "<div id=add9 align=middle style='color: " . GetColor($color)."; text-shadow: 1px 1px 1px black, 0 0 20px blue, 0 0 1px darkblue'>" .
   $row['score']. "</div></td><td><a href=delete.php?id=". $row['id'] . " data-placement='top' data-toggle='tooltip' title='Delete'><button class='btn btn-danger btn-xs' data-title='Delete' data-toggle='modal' data-target='#delete' </a><span class='glyphicon glyphicon-trash'></span></button></p></td>
</tr>".'' ;
}
?>

2nd Your css assignment to color looks incorrect:

Try this

color: ".$color.";
    
28.03.2017 / 20:14