0

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

3
Contributors
10
Replies
13
Views
4 Years
Discussion Span
Last Post by bradly.spicer
Featured Replies
0

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

Edited by radhakrishna.p: giving clarity solution

0

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)

Edited by radhakrishna.p: clarifying my solution

0

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

0

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?

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.