0
Return a query in a table that is mounted this way 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 do this if inside the while:
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
if ($maior < $teste = $rows_cursos['CGenericas1'])
$maior = $teste = $rows_cursos['CGenericas1'];
...
}
But now I intend that by finding the highest value in the first column, that puts color at the bottom of that cell, with the highest number in blue.
Anderson Carlos Woss, I’m trying to implement your suggestion, but I haven’t been able to get the desired result yet. After the code to find the highest value I am trying to compare 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 that is the highest value:
Complete code:
$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 .= '<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>';
}
Solution I found: I created a while to find only the greatest 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 where I compare the highest value with the value within 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>';
}
Upshot:
Inside your repeating loop that mounts the table, you can compare the current value with the higher value you found earlier. If they are equal, set the background to blue. Want to try?
– Woss
and if there are two or more equal values?
– user60252
@Leo Caracciolo, if you have two equal values you have to put both in blue background
– user130631
@Anderson Carlos Woss, I edited the question to show how I am trying to implement your suggestion, but it is not yet as I intend
– user130631
You are finding the biggest in the same loop you are displaying?
– Woss
@Anderson Carlos Woss, I edited the question with the full code. Yes, I’m showing in the same loop where I’m finding the highest value
– user130631
So this is a problem; you have how to know which will be the largest number without evaluating all the samples before.
– Woss
To clarify, you need to highlight the highest value in all columns?
– Woss
Yes, I need to know the highest value in these three columns and put blue background color, to identify the collaborator with the best performance in each of them
– user130631
@Anderson Carlos Woss, I managed to solve the problem, but I do not know if it is the best practice, I will edit the question with the solution I found
– user130631
You shouldn’t publish your solution within your question, you better answer your own question.
– user60252