mysql_fetch_array()的那些事,该怎么解决
程序员文章站
2022-04-29 14:53:18
...
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=".$
调试程序时出现这个问题: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