I return a query on a table that is set up like this in php:
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela2 .= '<td style="text-align: center; font: 10pt Arial;">'.$rows_cursos['AvaliacaoGlobal'].'</td>';
$tabela2 .= '<td style="text-align: center; font: 10pt Arial;">'.$rows_cursos['CGenericas1'].'</td>';
$tabela2 .= '<td style="text-align: center; font: 10pt Arial;">'.$rows_cursos['CEspecificas1'].'</td>';
}
To find the highest value in the first column I do this if within the while:
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
if ($maior < $teste = $rows_cursos['CGenericas1'])
$maior = $teste = $rows_cursos['CGenericas1'];
...
}
But now I want to find the highest value in the first column, which puts the background color of that cell, with the number greater than blue.
Anderson Carlos Woss, I'm trying to implement your suggestion, but I still can not get the result you want. After the code to find the highest value I am trying to compare it as follows:
if ($maior == $teste){
$cormaxGenericas = 'bgcolor=blue';
}else{
$cormaxGenericas = 'bgcolor=white';
}
The result is that you are putting blue background color in the first 3 cells, where you should only put blue color in the third one that is the largest value:
Completecode:
$maior=0;while($rows_cursos=mysqli_fetch_array($resultado_cursos)){if($maior<$teste=$rows_cursos['CGenericas1'])$maior=$teste=$rows_cursos['CGenericas1'];if($maior==$rows_cursos['CGenericas1']){$cormaxGenericas='bgcolor=blue';}else{$cormaxGenericas='bgcolor=white';}$tabela2.='<tdstyle="text-align: center; font: 10pt Arial;"'.$cormaxGenericas.'>'.$rows_cursos['CGenericas1'].'</td>';
$tabela2 .= '<td style="text-align: center; font: 10pt Arial;">'.$rows_cursos['CEspecificas1'].'</td>';
$tabela2 .= '<td style="text-align: center; font: 10pt Arial;">'.$rows_cursos['AvaliacaoGlobal1'].'</td>';
}
Solution I found: I created a while to find only the largest value:
while($rows_cursos1 = mysqli_fetch_array($resultado_cursos1)) {
if ($maior < $teste = $rows_cursos1['CGenericas1'])
$maior = $teste = $rows_cursos1['CGenericas1'];
}
Then I created the while while comparing the largest value with the value inside this new while:
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
if ($maior == $rows_cursos['CGenericas1']){
$cormaxGenericas = 'bgcolor=blue';
}else{
$cormaxGenericas = 'bgcolor=white';
}
$tabela2 .= '<td style="text-align: center; font: 10pt Arial;"'.$cormaxGenericas.'>'.$rows_cursos['CGenericas1'].'</td>';
$tabela2 .= '<td style="text-align: center; font: 10pt Arial;">'.$rows_cursos['CEspecificas1'].'</td>';
$tabela2 .= '<td style="text-align: center; font: 10pt Arial;">'.$rows_cursos['AvaliacaoGlobal1'].'</td>';
}
Result: