Jump to content

COUNT Not Working


Custer

Recommended Posts

Hey guys,

 

I'm trying to put up a table in PHP that displays how many players there are in the game. I followed proper syntax and everything, and the display I'm getting after the echo is 'Resource id #11'.

 

What am I doing wrong?

 

<?php
//connection
require ("../session.php");
require ("../configure.php");
mysql_connect ("$dbhost", "$dbuser", "$dbpass")or die("Could not connect: ".mysql_error());
mysql_select_db("$dbname") or die(mysql_error());

$query = mysql_query("SELECT COUNT(userid) FROM users") or die(mysql_error()); 


echo("<center><h1>Welcome ".$_SESSION['username']."</h1></center><br><table><tr><td>Number of 

Players</td><td><td>$query</td></tr><tr><td>Game Hour</td></tr></table>");
?>

Link to comment
https://forums.phpfreaks.com/topic/61067-count-not-working/
Share on other sites

no because userID doesn't have anythign to do with num users

you could do something like

<?php
$q = "select UserID From users ORDER BY UserID DESC LIMIT 1";
$r = mysql_query($q) or die(mysql_error());
$row = mysql_fetch_assoc($r);
$num_users = $row['UserID'];
?>

But that is only if your userID is auto incremented and the highest is assumed to be the total number of users

you can't do it without running a mysql_fetch_array type or a mysql_num_rows a mysql_query only is a sql resource it can't be purged for data only used in mysql functions

 

Edit: Yeah like what rlindauer said its a resource not a string/array/integer value

Link to comment
https://forums.phpfreaks.com/topic/61067-count-not-working/#findComment-303902
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.