【问题标题】:AVG mysql php error: mysql_fetch_array() expects parameter 1 to be resourcAVG mysql php 错误:mysql_fetch_array() 期望参数 1 是资源
【发布时间】:2014-11-10 21:44:56
【问题描述】:

我正在尝试从“valor_premio”列中获取平均值,但出现此错误:

Warning: mysql_query() expects parameter 1 to be string, resource given in /home/u566181585/public_html/index.php on line 61 Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/u566181585/public_html/index.php on line 63

第一个回显返回:Resource id #13

$sel2 = mysql_query( "SELECT AVG(valor_premio) as avg_valor FROM novaaaa WHERE categoria='Identidade'")  or (mysql_error());
echo $sel2;
$media_ident2=mysql_query($sel2);
echo $media_ident2;
$media_ident = mysql_fetch_array($media_ident2);
echo $media_ident;

怎么了?如何获得平均值?

【问题讨论】:

  • 您使用了两次mysql_query;删除一个。

标签: php mysql average


【解决方案1】:
$media_ident2=mysql_query($sel2);
                          ^^^^^

$sel2 是您之前的@​​987654323@ 调用的结果句柄。你不能使用这样的结果句柄。您必须提供一个包含您的 sql 作为参数的 STRING。

你想要的是

$sql = "SELECT ..."; // note: **NO** mysql_query() call...

$result = mysql_query($sql) or die(mysql_error());

【讨论】:

  • 谢谢@Marc B 我没有错误了,但是我从 $media_ident 得到了 return: Array.我应该如何获得号码?
猜你喜欢
  • 2012-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 2011-02-11
  • 2011-08-28
相关资源
最近更新 更多