2012-05-14 43 views
0

可能重複:
Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given errormysql_fetch_array()預計參數1是資源錯誤問題

我想呼應表的內容,但我得到一個錯誤與此代碼行:

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

$sql="SELECT * FROM $tbl_name ORDER BY id DESC"; 
// OREDER BY id DESC is order result by descending 
$result=mysql_query($sql); 

while($rows=mysql_fetch_array($result)){ // Start looping table row 
+1

我們需要看先前的代碼。你特定的'$ result = mysql_query(...)'語句是什麼? – benesch

+1

我們需要查看所有代碼來幫助解決問題。 – Drewdin

+0

我更新了代碼.. –

回答

0

添加,如果你開始循環之前狀態檢查$結果。 避免不必要的雙引號。

mysql_connect($host, $username, $password)or die("cannot connect"); 
mysql_select_db($db_name)or die("cannot select DB"); 

$sql="SELECT * FROM $tbl_name ORDER BY id DESC"; 
// OREDER BY id DESC is order result by descending 
$result=mysql_query($sql); 

if($result) 
{ 
    while($rows=mysql_fetch_array($result)){ 
     // Start looping table row 
    }//while end 
} 
else 
{ 
    echo "ERROR:".mysql_errno(); 
} 
相關問題