2013-10-16 48 views
1

有人可以幫我解決這個錯誤:mysql_num_rows()預計參數1是資源錯誤

mysql_num_rows()預計參數1是資源

這是我的代碼:

$query = mysql_query($query); 
$numrows = mysql_num_rows($query); 
if ($numrows > 0){ 
+0

嘗試: $查詢=請求mysql_query($查詢)或死亡(mysql_error()); 併發布錯誤結果。這是查詢可能無效的問題。 – Piotr

回答

0

你可以試試這個: -

$numrows = $query->num_rows; 
+0

這將禁止警告,但不會按預期工作。它不會正確返回行數 - 實際上它不會返回任何內容。 – Piotr

1

重命名你的變量名:

$result = mysql_query($query); 
$numrows = mysql_num_rows($result); 
if ($numrows > 0){ 
+0

這不是問題! $ query = mysql_query($ query); 以上代碼100%正確 – Piotr

+0

php文檔說明您必須以結果作爲參數。他傳遞的查詢和參數的相同變量名稱(http://php.net/manual/en/function.mysql-num-rows.php) – VancleiP

+1

如果您不知道... $ query variable在該行中從字符串更改爲結果類型。 PHP以這種方式工作 - thx,你可以做,例如$ i = 1; $ i = $ i + 1;結果將是2 ... – Piotr

0

試試這一個:

$result = mysql_query($query); 

if (!$result) { 
    die('Invalid query: ' . mysql_error()); 
} 
else { 
    $numrows = mysql_num_rows($result); 
     if ($numrows > 0){ 
     // put your code here 
     } 
    } 
相關問題