2012-10-27 76 views
-1
$query = "SELECT * FROM XXXX"; 
$result = mysql_query($query); 
$noOfRows = mysql_num_rows($result); 

如何檢查$result在得到mysql_num_rows的結果之前是否爲空?PHP-mysql_num_rows()期望參數1成爲資源

+0

使用'如果($結果)' – air4x

+3

請注意,'mysql_'擴展已被棄用 - http://news.php.net/php.internals/53799 – doublesharp

回答

1

您可以用三元操作符檢查$result並設置$noOfRows0如果是false

$query = "SELECT * FROM XXXX"; 
$result = mysql_query($query); 
$noOfRows = (false===$result)? 0 : mysql_num_rows($result); 
相關問題