Skip to main content
hectoro98972169
Participant
Aug 1, 2020 4:38 AM UTC
Question

validar consulta sql

al intenta validar una consulta con por ejemplo  if (!Datos) no detecta cuando no se encontro un registro,

probe con empty . count mysqli_num _rows y tampoco  me resolvieron el problema.

puede ser un problema de configuracion del php o dreamweaver?

    This topic is closed to new replies. Start a new post to keep the conversation going.

    2 replies

    Legend
    Aug 2, 2020 9:47 AM UTC

    What exactly are you trying to do? Are you trying to find out IF any records exist when querying your database and IF they don't return a message or do something else?

     

    Something like below where the number of rows are returned from the database query into a variable  - $numRows

     

    $conn = new mysqli('localhost' , 'username' , 'password' , 'databaseName');

    $sqlQuery = $conn->query("SELECT * FROM tableName WHERE id= '3'") or die($conn->error);
    $sqlQuery = $sqlQuery->fetch_assoc();
    $numRows = $sqlQuery->num_rows;

     

    If no results are found:

     

    if($numRows == 0) {

    Do Something

    }

    else {

    Do Something Else

    }

    Translate
    Nancy OShea
    Community Expert
    Community Expert
    Aug 1, 2020 8:26 PM UTC

    Don't blame the software.  Answers are contained in your code.

     

    Translate
    Nancy O'Shea— Product User & Community Expert