Custergrant 0 Report post Posted July 21, 2007 Hey guys,I'm currently trying to count a number of rows in a table and then echo it out as the number of players in my game. I've checked the SQL sites and I'm following proper syntax and everything. But when I view the page, I get 'Resource id #11', and not 3 like it should be...Below is the code: <?php//connectionrequire ("../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>");?> Maybe I should fetch an array, but the $query code should be executing, and I believe it is, because I'm getting the resource id, but it's not in the format it should be. Any of you have suggestions? Share this post Link to post Share on other sites
matak 2 Report post Posted July 21, 2007 (edited) You should use While loopWhile (case==true){echo something}while() Edited July 21, 2007 by matak (see edit history) Share this post Link to post Share on other sites
galexcd 0 Report post Posted July 23, 2007 (edited) Hey guys,I'm currently trying to count a number of rows in a table and then echo it out as the number of players in my game. I've checked the SQL sites and I'm following proper syntax and everything. But when I view the page, I get 'Resource id #11', and not 3 like it should be...Below is the code: <?php//connectionrequire ("../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>");?> Maybe I should fetch an array, but the $query code should be executing, and I believe it is, because I'm getting the resource id, but it's not in the format it should be. Any of you have suggestions? I've never used the COUNT function in SQL so I'm not exactly sure how it works but i'd suggest this:Instead of this line of code$query = mysql_query("SELECT COUNT(userid) FROM users") or die(mysql_error());try this$query = mysql_num_rows(mysql_query("SELECT * FROM users")); Edited July 23, 2007 by alex7h3pr0gr4m3r (see edit history) Share this post Link to post Share on other sites