Hey all,

Looking for some quick guidance, Trying to make it so that I can have a field which presents how many customers the database has.


This is the DB:


This is my php:

                        $id_customers = "SELECT id FROM Customers";
            $Customeramount = mysql_query($id_customers) or die(mysql_error()); 
            echo $Customeramount;

Result I am getting:

Resource id #2

Recommended Answers

So is this solved?

Jump to Post

All 10 Replies

i think its a bad idea to store no.of results in a seperate column. why because it has to modify seperately each and every customer is added to database as well as remove from the database.internally it increases no.of operation on a table

can you tell me the reason for your requirement?

so that i give the proper response to your question

Basically to show how many customers are in the database ^^

for that you have a query like count(*)....... something like this

or you can write some user_defined query to get the unique customers also

i think thats not a good way to store no.of customers in database (as of my knowledge)

Member Avatar

COUNT(id) would be my take. You can use GROUP BY functions to subtotal uniques.

Heres my revised code:

               $sql = "SELECT COUNT(ID)FROM Customers";
               $Customeramount = mysql_query($sql) or die(mysql_error());
               echo $Customeramount ;

It still returns this:

Sorry guys

Member Avatar

Stop providing screenshots. Place the answer in the editor. Your site will change and this thread will be worse than useless for others.


Should be valid - it works for my tables, even with the missing space and wrong case. Did you mis-spell the table or the field?

Still not working, should I post my whole script?


            $CustomerTableAmount = mysql_query("SELECT COUNT(ID) FROM Customers") or die(mysql_error());
            $row = mysql_fetch_row($CustomerTableAmount);
            echo $row[0];

Basically I wasn't using Mysql_Fetch_Row

Member Avatar

So is this solved?

Did click Solve, obviously didn't load properly :s