2013-01-05 37 views
-3

Possible Duplicate:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given警告:mysql_num_rows()預計參數1是資源,布爾線上給出26

我試圖讓我的論壇系統去,我不斷收到此錯誤:

警告:mysql_num_rows( )期望參數1是資源,布爾在第26行給出

大部分代碼只經歷了一個錯誤。這裏是我的全碼:

<?php 
include_once "../ads/connect_to_mysql.php";//Connect to Database 

//Get section ID from the url varible coming in 
if(isset($_GET['id'])&&$_GET[id]!=""){ 
    $sid=preg_replace('#[^0-9]#i','',$_GET['id']); //filter all characters except 
}else{ 
    echo "ERROR: Variables to run this script have been removed from the URL"; 
    exit(); 
} 
//Query the database for that section id, make sure it exists and get section title 
$sql=mysql_query("SELECT*From ad_sections WHERE id='$sid' LIMIT 1"); 
$numRows=mysql_num_rows($sql); 
if($numRows<1){ 
    echo "ERROR: That section does not exist, you have tampered with our URLs."; 
    exit(); 

} 
while($row=mysql_fetch_array($sql)){ 
    $sectionTitle=$row["title"]; 

} 
//Use the section ID to query a "ad_posts" table in the database to get all the threads for this section 
$sql=mysql_query("SELECT*From ad_sections WHERE type='a'AND section_id='$sid' ORDER BY date_time DESC LIMIT 25"); 
$dynamicList=""; 
$numRows=mysql_num_rows($sql); 
if($numRows<1){ 
    $dynamicList="There are no classifieds in this section yet. You can be the first to post."; 
}else{ 
    while($row=mysql_fetch_array($sql)){ 
    $thread_id=$row["id"]; 
    $thread_Title=$row["thread_title"]; 
    $dynamicList.='<a href="view_thread.php?id=' . $thread_id . '">' . $thread_Title . '</a><br/>'; 
    } 
} 
?> 

<!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"/> 
<title><?php echo "title"; ?></title> 
<style> 
</style> 
</head> 
<body> 
<table style="bacground-color: #f0f0f0; border:#069 1px solid; border-top:none; width="900"> 
<tr> 
<td width="731"><h2><?php echo $sectionTitle; ?><h2><?php echo $dynamicList; ?></td> 
<td width="189">&nbsp;</td> 
</tr> 
</table> 
</body> 
</html> 

這裏是第26行,真的只是碰了壁:

$numRows=mysql_num_rows($sql); 
+0

您沒有按照[manual。](http://php.net/mysql_query)中所述使用'mysql_error()'進行適當的錯誤檢查出於好奇,請問是否有教程那啓發了這個代碼?因爲我們經常得到這些問題,並且我一直在想有一個破碎的教程在那裏 –

+0

http://stackoverflow.com/search?q=Warning%3A+mysql_num_rows%28%29+expects+parameter+1+to + be +資源%2C +布爾+給出 –

回答

0

閱讀the manual

mysql_query() returns a resource on success, or FALSE on error.

...

mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.

0

其有關$sql是有錯誤

試試這個

$sql=mysql_query("SELECT * From ad_sections WHERE id='$sid' LIMIT 1"); 
          ^-^-----spaces here 
+1

也許不是,那就是它始終如一。 –

相關問題