Jump to content

[SOLVED] Count Register Users


Trium918

Recommended Posts

<?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

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

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?

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

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.