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.

E.g

This is the DB:

http://prntscr.com/o2vuf

This is my php:

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

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 for diafol

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

Heres my revised code:

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

It still returns this:
http://prntscr.com/o326w

Sorry guys

Member Avatar for diafol

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

SELECT COUNT(id) FROM Customers

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?

FIX:

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

Basically I wasn't using Mysql_Fetch_Row

Member Avatar for diafol

So is this solved?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.