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

WBOY
풀어 주다: 2016-06-13 13:35:58
원래의
861명이 탐색했습니다.

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으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!