Checking if there is a result in the query

-1

Hello, I need to check if there is an answer for my query. If it exists, it should display an HTML code displaying the bank's data. Otherwise you must notify that there is no result. How do I make this selection?

Example:

$sql = "select * from cronograma WHERE equipe='".$equipe."' AND datas='".$data."' "; 
$cronograma = mysqli_query($conexao, $sql);

//nesse ponto deve verifiar se existe resultado
if($cronograma = existe){
//exibe resultado da tabela}
else{ echo "Não existe resultado";}
    
asked by anonymous 10.10.2018 / 05:00

1 answer

0

If you want to know if the query got any result, greater than 0. You can use mysqli_num_rows to count the number of rows.

if(mysqli_num_rows($cronograma) > 0){
  // faça algo
}else{ echo "Não existe resultado";}

But if you just want to know if there was a successful connection, just do this:

if($cronograma){
   // faça algo
} else {
  // verifica o erro
  if(mysqli_errno($conexao) == 1064) echo "erro de sintaxe";
}

See the list of mysql error numbers that you can use.

    
10.10.2018 / 05:11