Change PHP/Html color

Asked

Viewed 47 times

2

I have the following problem and I believe that the JS can help, but I know almost nothing of JS.

I need the contents of the "td" tag if it equals "mount" to turn green and if it’s "wait" turn red.

        <input type="text" id="search" placeholder="Buscar">
        <table class="table table-dark table-hover" id="table">
            <caption>Operacao</caption>
            <thead>
                <tr>
                    <th>Ativo</th>
                    <th>Sinal</th>
                    <th>Cotação</th>
                </tr>
            </thead>
            <?php while ($linha = mysqli_fetch_assoc($result)) { ?>
                <tbody>
                    <tr>
                        <td><?= $linha['ATIVO'] ?></td>
                        <td><?= $linha['Robo PUT'] ?></td>
                        <td><?= $linha['Real Time'] ?></td>
                    </tr>
                </tbody>
            <?php } ?>
        </table>
  • I don’t think javascript is the best option to do what you want. You can apply a class (or inline styling) according to a condition in php. In which of the three td you want to change the color?

  • The middle line, where it should be the sign.

1 answer

1


Try something like:

<td <? if ($linha['Robo PUT'] == 'Montar'): echo "style='color: red;'"; endif; ?>>
   <?= $linha['Robo PUT'] ?>
</td>
  • Still not working... style="color: red;" > Mount this is the result on the screen.

  • I edited the answer. See now.

  • Perfect, thank you very much. I am deepening my studies in PHP.

Browser other questions tagged

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