RE: [PHP] multi-row count advice needed.
| From: | John W. Holmes | Date: | Fri, 08 Dec 2000 07:17:05 +0000 |
| Subject: | RE: [PHP] multi-row count advice needed. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31929@lists.php.net to get a copy of this message | ||
Couldn't you do something like this?
$result = mysql_query("SELECT foo,count(foo) FROM table GROUP BY foo");
while(list($var,$count) = mysql_fetch_row($result))
{
echo "$var occurs $count times<BR>\n";
}
Adapt to your needs...
---John Holmes...
-----Original Message-----
From: Jenny Koozer [mailto:jennykoozer@yahoo.com]
Sent: Wednesday, December 27, 2000 2:43 PM
To: php-general@lists.php.net
Subject: [PHP] multi-row count advice needed.
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