How to highlight a row in the query result php + sql

2

I'm developing an Application that uses a page PHP where I will have a ranking of points that the user makes when performing some interaction with it. I have a script that generates the list in order (from highest to lowest) showing from first place to last.

But I want to HIGHLIGHT the user who makes the query, passed through a form ( $ user = $ _GET ['user']; ), formatting his line in Bold. I think it's an IF condition but I can not get to the problem resolution.

  

Quote my current code, working perfectly, but without highlighting the user making the query.

  $usuario =$_GET['usuario'];

   $conexao = mysqli_connect('XXXXXXX','XXXXXX','XXXXXXX');
  mysqli_select_db($conexao,'XXXXXX');

 $sql="select * from login order by pontos DESC";

  $resultado = mysqli_query($conexao,$sql) or die ("Erro: " . mysqli_error());

$posicao = 1; //variavel

echo  <table width='90%' style='padding:10px;'><tr><td width='20%'><b>Class.</td><td width='60%'><b>Participante</td><td width='20%'><b>Pontos</td>";

//faz um looping e cria um array com os campos da consulta
while($array = mysqli_fetch_object($resultado)) {

echo "<tr><td>";
     echo $posicao;   // COLUNA DA POSIÇÃO NO RANKING

echo "</td><td>";

    echo $array->usuario; // AQUI EU QUERO UM IF PARA DIFERENCIAR O USUÁRIO PASSADO LÁ EM CIMA.

echo "</td><td>";
echo $array->pontos; // coluna dos pontos
echo "</td></tr>";
$posicao = $posicao + 1; // acumula próxima posição até terminar
} 

echo "</table>"
    
asked by anonymous 05.01.2016 / 20:13

2 answers

1
if($array->usuario == $usuario){
   echo '<strong>'.$usuario.'</strong>';
}else
   echo $usuario;
}
    
05.01.2016 / 20:22
2

Just as an add-on, an alternative with a ternary operator:

echo '</td><td>';
echo $array->usuario == $usuario ? '<strong>'.$usuario.'</strong>' : $usuario;
echo '</td><td>';

Do not forget to use htmlentities($usuario) in echo , if special characters like < > & etc are allowed in the name.

    
07.01.2016 / 04:00