可能重复:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given
我正试图让我的论坛系统继续运行并且我一直收到此错误:
警告: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"> </td>
</tr>
</table>
</body>
</html>
这是第26行,真的只是撞墙:
$numRows=mysql_num_rows($sql);
答案 0 :(得分:0)
阅读the manual:
mysql_query()在成功时返回资源,或在出错时返回FALSE。
...
mysql_query()也会失败,如果用户没有,则返回FALSE 有权访问查询引用的表。
答案 1 :(得分:0)
关于你的$sql
发生了错误
试试这个
$sql=mysql_query("SELECT * From ad_sections WHERE id='$sid' LIMIT 1");
^-^-----spaces here