Paint table row when receiving specific data

2

I have this code:

<?php
    foreach ($controller->Lista() as $objProg) {
?>
    <tr>
        <td><?php echo $objProg->getplaca(); ?></td>
        <td><?php echo $objProg->getmot(); ?></td>
        <td><?php echo $objProg->getsaida(); ?></td>
        <td><?php echo $objProg->getorig(); ?></td>
        <td><?php echo $objProg->getdest(); ?></td>
        <td><?php echo $objProg->getprev(); ?></td>
        <td><?php echo $objProg->getcarga(); ?></td>
        <td><?php echo $objProg->getadfin(); ?></td>
        <td><?php echo $objProg->getagen(); ?></td>
        <td><?php echo $objProg->getmal(); ?></td>
        <td class="t1" ><div><?php echo $objProg->getobs(); ?></div></td>
        <td><a href="edita.php?id=<?php echo $objProg->getid();?>"><p>Alterar</p></a></td>
    </tr>
<?php
    }
?>

I need to, when the echo $objProg->getdest(); is SP , paint the entire table row of a color. Any suggestions on how to do this? Do I need javascript anyway or is there any other method?

    
asked by anonymous 04.02.2016 / 20:16

2 answers

8

You can make a if in the tr tag.

<tr 
    <?php if ($objProg->getdest() == 'SP') { echo 'class="linha_destaque"'; } ?>
>

and creates a row-class in css

.linha_destaque{ background-color: red }

a table html example

<table>
  <thead>
    <tr>
      <th>Coluna 1</th>
      <th>Coluna 2</th>
    </tr>
  </thead>
  <tbody>
    <tr class="linha_destaque">
      <td>L1 - C1</td>
      <td>L1 - C2</td>
    </tr>
    <tr style="background-color: green">
      <td>L2 - C1</td>
      <td>L2 - C2</td>
    </tr>
    <tr>
      <td>L3 - C1</td>
      <td>L3 - C2</td>
    </tr>
    <tr>
      <td>L4 - C1</td>
      <td>L4 - C2</td>
    </tr>
  </tbody>  
</table>
    
04.02.2016 / 20:26
2

Add an if in the <tr> that checks if the state is SP if yes, add the class you want to paint the line, do not do anything.

<tr class="<?php if($objProg->getdest() == 'SP') echo 'especial'; ?>">

Sida is something like:

<tr class="especial">

Or

<tr class="">
    
04.02.2016 / 20:27