Page 1 of 1

record count

Posted: Sat Apr 01, 2006 7:20 am
by aceconcepts
Hi,

I have a mysql table that consists of orders made online. Every customer that orders products is inserted into this table.

How can i count how many orders a particular customer has made?

Thanks.

Re: record count

Posted: Sat Apr 01, 2006 7:50 am
by jmut
aceconcepts wrote:Hi,

I have a mysql table that consists of orders made online. Every customer that orders products is inserted into this table.

How can i count how many orders a particular customer has made?

Thanks.

Code: Select all

"SELECT COUNT(*) as orders_made GROUP BY customer_id"
Of course this all depends on you DB structure. But it is all about group by :D

Posted: Sat Apr 01, 2006 10:21 am
by John Cartwright
if you are already fetching all your results from a previous query, such as

Code: Select all

SELECT * FROM `orders` WHERE `customer_id` = 5
then you can simply use mysql_num_rows(), otherwise use jmut's suggestion