Trium918 Posted May 27, 2007 Share Posted May 27, 2007 I am looking for away to count the number of users in the database. What are some functions that I would I need? Example: Register Users = 50 Quote Link to comment Share on other sites More sharing options...
gabeg Posted May 27, 2007 Share Posted May 27, 2007 <?php $result = mysql_query("SELECT COUNT(id) as num FROM yourtable"); $row = mysql_fetch_object($result); echo "Registered Users: ".$row->num; ?> Quote Link to comment Share on other sites More sharing options...
Trium918 Posted May 27, 2007 Author Share Posted May 27, 2007 <?php $result = mysql_query("SELECT COUNT(id) as num FROM yourtable"); $row = mysql_fetch_object($result); echo "Registered Users: ".$row->num; ?> There is an error. Quote Link to comment Share on other sites More sharing options...
gabeg Posted May 27, 2007 Share Posted May 27, 2007 <?php $result = mysql_query("SELECT COUNT(id) as num FROM yourtable"); $row = mysql_fetch_object($result); echo "Registered Users: ".$row->num; ?> There is an error. Your table isn't called yourtable, have you changed that? Have you made a connection to the database before this? Is your primary index called id? This is just an example on how you would accomplish what you want to do, not something you can copy and paste into your current code. The most important part of what I posted is the query, it counts the rows and returns that number as column "num", but you must change the query to match your index names, and table name Quote Link to comment Share on other sites More sharing options...
Trium918 Posted May 27, 2007 Author Share Posted May 27, 2007 I change all of that! I knew that. Quote Link to comment Share on other sites More sharing options...
gabeg Posted May 27, 2007 Share Posted May 27, 2007 I change all of that! I knew that. What is the error? I've tested this on my own database and it works Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 27, 2007 Share Posted May 27, 2007 And the error is .... ? You might want to structure things better so as to enable rational error display ... Change $result = mysql_query("SELECT COUNT(id) as num FROM yourtable"); to: $query = "SELECT COUNT(id) as num FROM yourtable"; $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // see if that helps Quote Link to comment Share on other sites More sharing options...
Trium918 Posted May 27, 2007 Author Share Posted May 27, 2007 lol, Thanks. I works. } brace left from a early code. Quote Link to comment Share on other sites More sharing options...
Trium918 Posted May 27, 2007 Author Share Posted May 27, 2007 What if I had there were a total of 100000 users. What what is the php function that will display the total as 100,000? Quote Link to comment Share on other sites More sharing options...
gabeg Posted May 27, 2007 Share Posted May 27, 2007 What if I had there were a total of 100000 users. What what is the php function that will display the total as 100,000? This function simply counts the rows the database, as you add rows, the number returned will increase by the same amount. Quote Link to comment Share on other sites More sharing options...
Trium918 Posted May 27, 2007 Author Share Posted May 27, 2007 What if I had there were a total of 100000 users. What what is the php function that will display the total as 100,000? This function simply counts the rows the database, as you add rows, the number returned will increase by the same amount. The comma is added automatically, correct? Quote Link to comment Share on other sites More sharing options...
gabeg Posted May 27, 2007 Share Posted May 27, 2007 What if I had there were a total of 100000 users. What what is the php function that will display the total as 100,000? This function simply counts the rows the database, as you add rows, the number returned will increase by the same amount. The comma is added automatically, correct? No, you will need to use http://us.php.net/numberformat on the result Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.