Search code examples
phpmysqlinotnull

Unexpected Mysqli WHERE is not null Value Returned


Mysqli query to a table containing rows of data.

When i use this SELECT it returns no rows when a row does exist with the desired request.

I have written this several ways of which i have seen on various references but all return no rows.

I wish to retrieve(SELECT) the latest(DESC)(LIMIT 1) row by(datetime_upload) in full(*) WHERE (licensePath) has something in the cell(IS NOT NULL).

Q. I would like to know what i need to adjust in my select statement to return the desired result?

MySQL Table

The Select:

$query = "SELECT * FROM driver_docs WHERE driver_profileId LIKE '$uid' AND WHERE licensePath IS NOT NULL ORDER BY datetime_upload DESC LIMIT 1";
    $result = mysqli_query($conn, $query);
    $row = mysqli_fetch_array($result, MYSQLI_ASSOC);

    if ($row) { 
        if ($row["licensePath"]) {
            echo "license";
        } 
    }
    else {
        echo "NO ROWS";
    }

Solution

  • A null value and empty value is not the same. As your cell is var_char your text would automatically be shown as an empty value. Which would mean you do != '' instead of IS NOT NULL.

    Most likely a NULL value is typed out as NULL.

    -written on a phone in the bus on my way home. Excuse me for grammatical errors and/or unfinished answering.