2011-05-08 96 views
1

可能重複:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in selectmysql讀取數組錯誤?

我得到在我的劇本Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\FBlike\like.php on line 104 .. 我不知道這意味着什麼,以及爲什麼它正在發生...幫助:)?

$like_id=mysql_real_escape_string($_GET['id']); 

$sql=mysql_query("select * from likes WHERE id=$like_id DESC LIMIT 1"); 
while($row=mysql_fetch_array($sql)) 
{ 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

    <meta name="description" content="<?php print $row['like']; ?>"/> 

    <meta name="keywords" content="<?php print $row['like']; ?>" /> 

    <meta property="og:description" content="Click to See More..." /> 

     <meta property="fb:app_id" content="" /> 



    <meta property="og:title" content="<?php print $row['like']; ?>"/> 

    <meta property="og:type" content="activity"/> 

    <meta property="og:url" content="http://www.fbquote.me/like.php?id=<?php print $row['id']; ?>" /> 

    <meta property="og:site_name" content="pDank" /> 
<title><?php print $row['like']; ?></title> 

<?php } ?> 
+0

我會檢查上次mysql_error()調用mysql_fetch_array(前) – Scuzzy 2011-05-08 23:32:11

回答

1

您的SQL查詢中有錯誤。

mysql_fetch_array()之前添加以下代碼:

if (!$sql) { 
    die(mysql_error()); 
} 
2

mysql_query()回報FALSE上的錯誤,ERGO在查詢中有一個錯誤。

使用mysql_error()獲取最後一條錯誤消息。

例如

$result = mysql_query("select * from likes WHERE id=$like_id DESC LIMIT 1"); 
if (false === $result) { 
    throw new Exception('MySQL error: ' . mysql_error()); 
} 
0

這意味着您的查詢某種原因失敗(無效語法,列沒有找到......),並返回FALSE。

爲了捕獲該問題,請檢查$ sql(實際上,您應該命名變量$ result或類似的,這更常見($ sql通常用於查詢字符串))爲FALSE,如果是這樣,print/log無論函數mysql_error()是否返回。