选择两个表并获取信息

时间:2014-08-04 21:46:15

标签: mysql

我尝试制作此功能时出错:

 function get_score_by_id($server_id){
 $server_id = sanitize($server_id); 
 $query = mysql_query("SELECT votes.COUNT(votes.*) as number_of_votes ,
 SUM(graphic.online) / (SUM(graphic.offline) + SUM(graphic.online))*100 as uptime,
 graphic.MAX(graphic.Players) as maxp
 FROM votes,graphic WHERE server_id = '$server_id'");
 $data = mysql_fetch_assoc($query);
 return (0.60 * $data['number_of_votes'])
  + (0.25 * $data['uptime']) 
  + (0.15 * $data['maxp']);
}

错误:

  Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in line 189

1 个答案:

答案 0 :(得分:0)

尝试修复COUNT ..将votes.COUNT()更改为COUNT() - graphic.MAX()改为MAX()

SELECT COUNT(v.id) AS number_of_votes ,
       SUM(g.online) / (SUM(g.offline) + SUM(g.online))*100 AS uptime,
       MAX(g.Players) AS maxp
FROM votes v,graphic g
WHERE v.server_id = '$server_id'