mysql_fetch_assoc() expects parameter 1 to be resource,怎么解决?

kafein 2010-11-20 10:55:12
执行时出错:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\index.php on line 10


In - posted on Thu Jst January 1970 12.00AM

No database selected





网页源码如下:
<?php
require("header.php");
$db=mysql_connect($dbhost,$dbuser,$dbpassword);
mysql_select_db($dbdatabase,$db);
$sql="SELECT entries.*,categories.cat FROM
entries,categories
WHERE entries.cat_id=categories.id
ORDER BY dateposted DESC
LIMIT 1;";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
echo "<h2><a href='viewentry.php?id=".$row
['id']."'>".$row['subject']."</a></h2><br />";
echo "<i>In <a href='viewcat.php?id=".$row
['cat_id']."'>".$row['cat']."</a> - posted on ".date("D
JS F Y g.iA",
strtotime($row['dateposted']))."</i>";
if(isset($_SEESION['USERNAME'])==TRUE){
echo "[<a href='updateentry.php?id=". $row['id']
."'>edit</a>]";
}
echo "<p>";
echo nl2br($row['body']);
echo "</p>";
echo "<p>";
$commsql="SELECT name FROM comments WHERE
blog_id=".$row['id']." ORDER BY dateposted;";
$commresult=mysql_query($commsql);
if(!$commresult){
echo mysql_error();
exit;
}
$numrows_comm=mysql_num_rows($commresult);
if($numrows_comm==0){
echo "<p>没有评论.</p>";
}
else
{
echo "(<strong>".$numrows_comm."</strong>) 评论:";
$i=1;
while($commrow=mysql_fetch_assoc($commresult)){
echo "<a href='viewentry.php?id=".$row
['id']."#comment".$i."'>".$commrow['name']."</a>";
$i++;
}
}
echo "</p>";
$prevsql="SELECT entries.*,categories.cat FROM
entries,categories
WHERE entries.cat_id=categories.id
ORDER BY dateposted DESC
LIMIT 1,5;";
$prevresult=mysql_query($prevsql);
$numrows_prev=mysql_num_rows($prevresult);
if($numrows_prev==0){
echo "<p>无任何记录.</p>";
}
else{
echo "<ul>";
while($prevrow=mysql_fetch_assoc($prevresult)){
echo "<li><a href='viewentry.php?id=".$prevrow
['id']."'>".$prevrow['subject']."</a></li>";
}
}
echo "</ul>";
require("footer.php");
?>
...全文
3311 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kafein 2010-11-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lure2222 的回复:]

你数据库中没有一行满足你的SQL语句
[/Quote]
不会啊,我在phpmyadmin中运行查询语句没问题啊
thisboy_star 2010-11-22
  • 打赏
  • 举报
回复
echo 一下SQL语句,然后在phpadmin当中运行一下看看。
lure2222 2010-11-22
  • 打赏
  • 举报
回复
你数据库中没有一行满足你的SQL语句
不喝水的鱼 2010-11-22
  • 打赏
  • 举报
回复
你数据库链接中参数从哪儿传的值啊?

网页源码如下:
<?php
require("header.php");
$db=mysql_connect($dbhost,$dbuser,$dbpassword);//这部分
mysql_select_db($dbdatabase,$db);
$sql="SELECT entries.*,categories.cat FROM
entries,categories
WHERE entries.cat_id=categories.id
ORDER BY dateposted DESC
LIMIT 1;";
$result=mysql_query($sql);
kafein 2010-11-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 alex_best 的回复:]

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\index.php on line 10


In - posted on Thu Jst January 1970 12.00AM

No database selecte


第一种……
[/Quote]
我看了下,数据库连接没问题,以前用的时候,根本没出现这种问题,这是在我安装xampp环境后出来的,网上有的说是编码的问题,但是我用的都是utf-8的码,应该不会有问题才是啊。
igaojie 2010-11-20
  • 打赏
  • 举报
回复
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\index.php on line 10


In - posted on Thu Jst January 1970 12.00AM

No database selecte


第一种可能:No database selecte
第二种可能:将你的sql语句打印出来 然后phpmyadmin运行一下

21,882

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧