How do I make conditional formatting on my php page?

-1

I have a table and I would like to create a conditional formatting for when certain text appears in the table, which are 5 such texts, (Start, half, end, canceled, awaited). change the font color, for each text a different color. Aguem know how to do this? Thanks

<table id="destino" class="table table-bordered table-striped">
            <thead>
             <tr>
              <th>ID</th>
              <th>Nome</th>
              <th>Cliente</th>
              <th>Data</th>
              <th>Destino</th>
             </tr>
            </thead>
            <tbody>
            <?php while($dado = $con->fetch_array()){ ?>
            <tr>
            <td><?php echo $dado["id"];?></td>
            <td><?php echo $dado["nome"];?></td>
            <td><?php echo $dado["cliente"];?></td>
            <td><?php echo $dado["data"];?></td>
            <td><?php echo $dado["destino"];?></td>
            </tr>
            <?php } ?>
            </tbody>                
            </tfoot>        
           </table>

In the Destination column where these specific text will appear.

    
asked by anonymous 17.06.2016 / 04:56

1 answer

0

Do so. At the beginning of your page, where you render PHP, create an associative array of values and colors:

<?php
$color = array(
           'Inicio' => '#cor1', 
           'metade' => '#cor2', 
           'fim' => '#cor3', 
           'cancelado' => '#cor4', 
           'aguardado' => '#cor5'
         );
?>

Remembering that #cor is hex code, of type #000000 .

Then on your page, more precisely on line <td><?php echo $dado["destino"];?></td> do:

<td style='color: <?= $color[$dado["destino"]] ?>'><?php echo $dado["destino"];?></td>

In this way the correct position in the array will return the hex of the color and you will have an inline style with the conditional color.

    
17.06.2016 / 05:48