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: 
From the [documentation](http://www.php.net/manual/en/function.isset.php):

> 
> isset -
> Returns TRUE if var exists and has value other than NULL, FALSE otherwise.
> 
> 
> 

But `$result` will be a valid MySQL resouce - event if there are no results from the query.

From the [docs](http://www.php.net/manual/en/function.mysql-query.php):

> 
> For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql\_query() returns a resource on success, or FALSE on error.
> 
> 
> For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql\_query() returns TRUE on success or FALSE on error.
> 
> 
> 

Use [`mysql_num_results()`](http://www.php.net/manual/en/function.mysql-num-rows.php) to detect whether the result set is empty or not:

```
if(mysql_num_rows($result) == 0) {
    echo 'no results';
}

```

---

Further note, that you should not use mysql\_\* functions for new code as the extension has been marked deprectated by the PHP developers. Use [`PDO`](http://www.php.net/manual/en/book.pdo.php) or [`mysqli`](http://www.php.net/manual/en/book.mysqli.php) instead.
Don't forget that `mysql_query` can return `false`, so:

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

```