Re: How to count same text results from DB?

From: Date: Tue, 03 Oct 2000 13:33:18 +0000
Subject: Re: How to count same text results from DB?
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-3262@lists.php.net to get a copy of this message
At 9:37 AM +0200 10-03-2000, Vojtech Dvorak wrote:
Hi, I have made select such as SELECT name, age FROM users WHERE age=18 I need to have at final something like: There is 27 Johns, 30 Pauls, 13 Marks etc. But few problems to make it harder: 1) I can't use more than one select, because this database is very slow (M$ Access) 2) I don't know names in database (in that case I would make If $name==John {$john++} clauses)
Sorry, but you can't get what you want with a single SQL statement. If you want the name + age results *and* a count of the number of instances of each name, you'll have to either use two queries, or (as you seem to suggest below), run through the results of the first query (shown above) and count the number of instances of each distinct name.
I was thinking about fetching all names in array and than count it somehow.... Please PHP Gurus help. Thx Vojtech
-- Paul DuBois, paul@snake.net

« previous php.db (#3262) next »