首页 > 后端开发 > php教程 > mysql_fetch_array()的那些事,该怎么解决

mysql_fetch_array()的那些事,该怎么解决

WBOY
发布: 2016-06-13 10:17:33
原创
835 人浏览过

mysql_fetch_array()的那些事
调试程序时出现这个问题:mysql_fetch_array() expects parameter 1 to be resource, boolean given in
请问是什么问题?
程序如下:
$result2=mysql_query("select sum(score) as sum from ask_score where qid=".$qid."and answerid=".$authid);
$author3 = mysql_fetch_array ( $result2, MYSQL_ASSOC );
$scoresum=$author3["sum"];

$result3=mysql_query("select count(*) as count from ask_score where qid=".$qid);
$author4 = mysql_fetch_array ( $result3, MYSQL_ASSOC );
$scorenum=$author4["count"];
ask_score表:
CREATE TABLE ask_socre(
qid int(10) unsigned NOT NULL default '0',
authorid mediumint(8) unsigned NOT NULL default '0',
answerid mediumint(8) unsigned NOT NULL default '0',
vote_id mediumint(8) unsigned NOT NULL default '0',
score int(2) unsigned NOT NULL default '0',
PRIMARY KEY (qid,authorid)
);

------解决方案--------------------
你的mysql_query返回了一个false,sql语句错误
改成mysql_query(...) or die(mysql_error()); 看sql语句有什么错误
------解决方案--------------------
1.表名
2.加点空格,最好加上单引号
where qid=".$qid."and answerid=".$


where qid=".$qid." and answerid=".$


PHP code
<?php$qid = '1';$authid = '1';$link = mysql_connect('127.0.0.1', 'root', '');mysql_select_db("test");$sql2= " select sum(score) as sum from ask_socre where qid='".$qid."' and answerid='".$authid."' ";$result2=mysql_query($sql2);echo $sql2;if($author3 = mysql_fetch_array ( $result2, MYSQL_ASSOC )){     var_dump($author3);    $scoresum=$author3["sum"];}$sql3 = "select count(*) as count from ask_socre where qid='".$qid."' ";$result3=mysql_query($sql3);echo $sql3;if($author4 = mysql_fetch_array ( $result3, MYSQL_ASSOC )){     var_dump($author4);    $scorenum=$author4["count"];}<div class="clear"></div>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板