record count

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

record count

Post 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.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: record count

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
Post Reply