Show message if php records do not appear

1

The problems that I present are the following, since I am trying that when I search for something it shows me what I am looking for but if it does not find anything then it shows a message of does not exist, the question is that it already shows me the message of exists , but it does not show me the one that does not exist

This is the code

    <?php
    include "mysqlcon.php";
    $con = connect();
    if(isset($_POST['opcion']) && isset($_POST['datos'])){
    $opcion = $_POST['opcion'];
    $datos = $_POST['datos'];
        if ($opcion == 1) {
      $consulta = "SELECT * FROM info WHERE cedula = $datos"; 
    }
    if($opcion == 2){
      $consulta = "SELECT * FROM info WHERE telefono = $datos"; 
    }
    $resultado = mysqli_query($con, $consulta);
    $contador = 0;
    while ($misdatos = mysqli_fetch_assoc($resultado));
    if (mysqli_num_rows($resultado)>0)
      {
      echo(" Exite registro");
      } else {
      echo("No Existen registros");
      }
}
?>

What I am omitting or where my error is.

Thanks for the help !!!

    
asked by angel ramirez 22.10.2018 в 17:56
source

1 answer

2

The method to count the number of records mysqli_num_rows goes out of the while, like this:

if (mysqli_num_rows($resultado)>0)
{
   echo(" Exite registro");
   // despues de verificar que si hay registro recorres el objeto
   while ($misdatos = mysqli_fetch_assoc($resultado))
   {
       // imprimes los registros
   }
} else {
   echo("No Existen registros");
}
    
answered by 22.10.2018 / 18:15
source