Re: How to count same text results from DB?

From: Date: Tue, 03 Oct 2000 10:23:45 +0000
Subject: Re: How to count same text results from DB?
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-3255@lists.php.net to get a copy of this message
What I would do is: $alldata=array(); $alldata=suck_all_data_into_an_array(); for ($i=0 ; $i<count($alldata) ; $i++) { $mycount[ $alldata["NAME"][$i] ] ++; do_your_stuff(); } reset($mycount) while (list($k,$v) = each($mycount)) { echo "There are $v students with the name $k<br>"; } Is this more what you want? David. ----- Original Message ----- From: Vojtech Dvorak <vojtech_dvorak@servind.cz> To: David Newcomb <davidn@vnvi.com> Sent: Tuesday, October 03, 2000 10:56 AM Subject: Re: [PHP-DB] How to count same text results from DB? > Hi David, > It's easy, I need to know how many Johns (or Marks, Peters whoever..) are > old 18 years. > I know I can use COUNT and GROUP BY, but this means to use two selects, > because I need more than this from this one select. > As I just send to conference I have basic select like this > +++ > SELECT name, class, age, descr, tech, local > FROM users > WHERE class=3A > ++++ > > So I want to make that counting in each loop of my basic select. > That's all > Thanks for any help > Vojtech > > > > > > What is your question? > > How to count the result? > > select count(*) from users where age=18 > > or > > select count(*), name,age from users where age=18 > > > > ----- Original Message ----- > > From: Vojtech Dvorak <vojtech_dvorak@servind.cz> > > To: <php-db@lists.php.net> > > Sent: Tuesday, October 03, 2000 8:37 AM > > Subject: [PHP-DB] How to count same text results from DB? > > > > > > > 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) > > > > > > I was thinking about fetching all names in array and than count it > > > somehow.... > > > Please PHP Gurus help. > > > Thx > > > Vojtech > > > > > > > > > > > > -- > > > PHP Database Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-db-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > For additional commands, e-mail: php-db-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > >

« previous php.db (#3255) next »