Question: I have a php page with the code below. The MySQL query is working correctly but I have tried adding an IF statement which isn't working. The `if(!isset($result))` statement is supposed to catch situations where the table only contains FUTURE datetime values. I'm obviously not using it correctly or I should be using something else - like `if(empty())`? 

```
<?php

include 'quantitytest_config.php';

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
  or die("Unable to connect to MySQL");

//select a database to work with
$selected = mysql_select_db("grace59_countdown",$dbhandle) 
  or die("Could not select countdown");

//execute the SQL query and return records
$result = mysql_query(
    "SELECT items 
    FROM cases 
    WHERE datetime<=NOW()
    Limit 1 ");

// check if there are only future dates in Database
if(!isset($result)){
    echo "9999";
} else {

//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
   echo "Quantity:".$row{'items'}."<br>";
}
}
//close the connection
mysql_close($dbhandle);
?>

```

Answer: 
You are looking for:

```
if(mysql_num_rows($result) == 0){
   echo "9999";
} else {

```

Documentation: <http://www.php.net/manual/en/function.mysql-num-rows.php> 

You assign a value to $result when you say `$result = mysql_query` so even if no rows are found, the variable is now set, so `isset()` won't help.

But you should really not use mysql\_\* functions. Look after prepared statements instead. PDO or mysqli. Further reading can be found here: <http://www.php.net/manual/en/function.mysql-query.php> (the red box)
Don't forget that `mysql_query` can return `false`, so:

```
if($result){
    if(mysql_num_rows($result) == 0){
        echo "9999";
    }
}

```