Coloring a field in a column according to parameters

0

I have a table with 5 columns and 2 records. One of the fields in the record is a number (noteQualif), I need the field in which it is inserted to be painted green if it is larger than 75 and painted red if it is smaller than 75.

All data is stored in a database created in phpmyadmin, so it is necessary that when the user enters data, the note Queualif is checked and soon painted in green or red.

I leave here the code made so far that it looks at the table with the data.

<head><title>Ver registos</title></head>

<?php
    LigarBDfater(); //connect to the database


    // get results from database
    $result = mysql_query("SELECT * FROM qualificacao") or die(mysql_error());


    // display data in table
    echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>";
    echo "<table border='1' cellpadding='10'>";
    echo "<tr><th>ID Qualifica&ccedil;&atilde;o</th> <th>ID Fornecedor</th> <th>Nome Funcionario</th> <th>Nota Qualifica&ccedil;&atilde;o</th> <th>Data Qualifica&ccedil;&atilde;o</th></tr>";


    // loop through results of database query, displaying them in the table
    while($row = mysql_fetch_array($result)){

        // echo out the contents of each row into a table
        echo "<tr>";
        echo '<td>' . $row['id_qualific'] . '</td>';
        echo '<td>' . $row['id_fornecedor'] . '</td>';
        echo '<td>' . $row['nomeFuncionario'] . '</td>';
        echo '<td>' . $row['notaQualif'] . '</td>';
        echo '<td>' . $row['dataQualif'] . '</td>';
        echo "</tr>";
    }

    // close table>
    echo "</table>";
?>

<p align="left"><a href="novo_qualificacao.php">Adicionar um novo registo</a></p>

    
asked by anonymous 09.02.2017 / 16:54

1 answer

1

Make the following change in your PHP:

if($row['notaQualif'] > 75) echo '<td class="bgVerde">' . $row['notaQualif'] . '</td>';
else echo '<td class="bgVermelho">' . $row['notaQualif'] . '</td>';

And in the styles apply:

td.bgVerde {
  background-color: #07CC36;
  color: #FFF;
}
td.bgVermelho {
  background-color: #c12536;
  color: #FFF;
}
    
09.02.2017 / 18:40