我有一个带有以下代码的 php 页面。MySQL 查询工作正常,但我尝试添加一个不起作用的 IF 语句。该if(!isset($result))
语句应该捕获表仅包含 FUTURE 日期时间值的情况。我显然没有正确使用它,或者我应该使用其他东西 - 比如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);
?>