change line color

Asked

Viewed 79 times

0

Hello, I am trying to change the colors of the lines according to each status, for example, if the status is canceled paint red, if it is allowed to paint green. I tried to put an if, but it’s not working and the worst thing is that there is no error on the screen. the page I want to change is this... Could someone check for syntax error?! Thank you

inserir a descrição da imagem aqui

  • Where you want to change the color, put the HTML in the question and use bootstrap for example

  • Welcome to Stackoverflow, dude, always try to post as much information as possible as the complete code, where the problem is, and if there is an error log. This information is essential to be able to help you. Always try to be as clear and objective as possible in the questions. :)

  • Best you paste the content, not print.

1 answer

2

But following your ideology, you can do it this way:

<table>
    <tr>
        <td>ID</td>
        <td>Nome</td>
        <td>Email</td>
        <td>Status</td>
    </tr>
    <?php 
    foreach($consulta as $valor){ 
    if($valor->status==1){
        $cor = "#FFCC00";
    } else {
        $cor = "#EDEDED";
    }
    ?>
    <tr bgcolor="<?php echo $cor; ?>">
        <td><?php echo $valor->id; ?></td>
        <td><?php echo $valor->nome; ?></td>
        <td><?php echo $valor->email; ?></td>
        <td><?php echo $valor->status; ?></td>
    </tr>   
    <?php } ?>
</table>

This way we assign $color according to the status, if it is 1 (in the inactive case), we put orange as bg, if it is 0, then we put gray.

  • In my opinion I would not do ==, would only do ==, and would use instead of canceled, status 1, 2, 3.. I think it gets more organized, and create in the bank the Enum to determine that

Browser other questions tagged

You are not signed in. Login or sign up in order to post.