Php – How to echo a query

MySQLPHP

Possible Duplicate:
Why does this return Resource id #2?

I want to echo mysql_query("SELECT SUM(onlineplayers) FROM servers") but when I place echo in front, it says Resource Id #2 and when I add or die(mysql_error()); at the end, it just outputs 1.

Best Answer

You need to fetch the query first:

$result = mysql_query("SELECT SUM(onlineplayers) FROM servers");
if($result){
  $data = mysql_fetch_assoc($result);
  echo $data[0];
}

However, you shouldn't use the mysql_ functions unless absolutely necessary. the mysql extension is NOT recommended for use in new projects. Instead you should use PDO_mysql or mysqli

Source: Why does this return Resource id #2?