Converting a result from mysqli_query () to String

-1

First, I'm not good at writing, but I'll try to explain the problem

I need to print only one cell (number of votes already made) from the result table of the query, but not so I can access the value of the conversion error.

I was having to do the query and the echo directly in the function call in html

The votes need this after the name description

function pegarQtdVotos($conexao,$classificacao){
    $query = "select qtd_votos from VOTOS where id={$classificacao}";
    $resultado = mysqli_query($conexao, $query);
    $qtd = mysqli_fetch_assoc($resultado);
    return $qtd;
}

<p class="alert-success"><input type="radio" name="classificacao" id="classificacao" value="1"> Execelente</p>
<p class="alert-info"><input type="radio" name="classificacao" id="classificacao" value="2"> Bom </p>
<p class="alert-warning"><input type="radio" name="classificacao" id="classificacao" value="3"> Regular </p>
<p class="alert-danger"><input type="radio" name="classificacao" id="classificacao" value="4"> Ruim </p>
                                        
    
asked by anonymous 17.04.2018 / 03:16

1 answer

2

If you print inside the function will work!

function pegarQtdVotos($conexao,$classificacao){

   $query="select qtd_votos from VOTOS where id={$classificacao}"; 
   $resultado=mysqli_query($conexao,$query);

   $qtd = mysqli_fetch_assoc($resultado);

   //return $qtd;    
   echo $qtd["qtd_votos"];

}

while is PHP's simplest repeat structure. With it we inform that a block of code must be repeated while the stated condition is true.

$query = "select qtd_votos from VOTOS where id={$classificacao}"; 
$resultado = mysqli_query($conexao, $query); 
 while ($rows = mysqli_fetch_assoc($resultado)) { 
   echo $rows['qtd_votos'];
}; 
    
17.04.2018 / 15:53