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 Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/ 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; ?> Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262834 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. Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262837 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 Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262838 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. Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262839 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 Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262840 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 Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262841 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. Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262842 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? Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262846 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. Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262848 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? Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262852 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 Link to comment https://forums.phpfreaks.com/topic/53198-solved-count-register-users/#findComment-262854 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.