-1
$query = "SELECT * FROM XXXX";
$result = mysql_query($query);
$noOfRows = mysql_num_rows($result);
如何檢查$result
在得到mysql_num_rows
的結果之前是否爲空?PHP-mysql_num_rows()期望參數1成爲資源
$query = "SELECT * FROM XXXX";
$result = mysql_query($query);
$noOfRows = mysql_num_rows($result);
如何檢查$result
在得到mysql_num_rows
的結果之前是否爲空?PHP-mysql_num_rows()期望參數1成爲資源
您可以用三元操作符檢查$result
並設置$noOfRows
到0
如果是false
:
$query = "SELECT * FROM XXXX";
$result = mysql_query($query);
$noOfRows = (false===$result)? 0 : mysql_num_rows($result);
使用'如果($結果)' – air4x
請注意,'mysql_'擴展已被棄用 - http://news.php.net/php.internals/53799 – doublesharp