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

WBOY
發布: 2016-06-13 10:17:33
原創
823 人瀏覽過

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">
                 
              
              
        
            
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板