Re: multi-row count advice needed.
| From: | Cynic | Date: | Wed, 27 Dec 2000 06:14:57 +0000 |
| Subject: | Re: multi-row count advice needed. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31923@lists.php.net to get a copy of this message | ||
Don't know which one is faster, but you can always bench
all possible solutions...
switch( $row['foo'] ) {
case 'a' :
case 'b' :
case 'c' :
$count[ $row['foo'] ]++ ;
break ;
default:
$count['z']++ ;
break ;
}
*********************
if( 'a' == $row['foo'] || 'b' == $row['foo'] ||
'c' == $row['foo'] ) {
$count[ $row['foo'] ]++ ;
} else {
$count['z']++ ;
}
BTW, hardware is cheaper than programmer time.
At 06:42 27.12. 2000, Jenny Koozer wrote the following:
--------------------------------------------------------------
>Hi all!
>
>I have a bunch of rows and am counting the "number of
>instances" within each. Here's what I've figured thus
>far, am looking for tips on "doing it more
>efficiently" as to lesson workload on server :
>
>$result = mysql_query("SELECT foo FROM table");
>
>while($row = mysql_fetch_array($result)) {
>
> if ($row['foo'] == 'a') { $count['a']++; }
> elseif ($row['foo'] == 'b') { $count['b']++; }
> elseif ($row['foo'] == 'c') { $count['c']++; }
> else { $count['z']++; }
>
>}
>
>Created is an array full of row totals, which is
>desired. Other ways to do this?
>
>TIA!
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Shopping - Thousands of Stores. Millions of Products.
>http://shopping.yahoo.com/
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
------end of quote------
____________________________________________________________
Cynic:
A member of a group of ancient Greek philosophers who taught
that virtue constitutes happiness and that self control is
the essential part of virtue.
cynic@mail.cz