bags o beans - filtering rows/array by value of an aggregated attribute
| From: | Grant Listhandle | Date: | Thu, 05 Aug 2004 22:26:05 +0000 |
| Subject: | bags o beans - filtering rows/array by value of an aggregated attribute | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35599@lists.php.net to get a copy of this message | ||
In the database "beans" i have a table "bags_o_beans" where each row
represents a single bag, and columns named "bean_type" and "number_o_beans"
My teenage son is having several thousand hungry friends over in half an
hour, and I'm stuck making the bean dip... I'm going to need 1 million
beans of a single type to make the dip.
My goal, before I start cooking, is to filter from the following query:
SELECT bean_type, sum(number_o_beans) FROM bags_o_beans GROUP BY bean_type
...into an html table such that only 'bean types' with
'sum(number_of_beans)' greater than 1 million are displayed. I have tried
inserting the following snippet into the table-generating php code, with no
luck:
while ($row = @ mysql_fetch_row($result))
{
foreach($row as $data)
if ({sum(number_o_beans)} > (1000000))
print "\n\t<td> {$data} </td>";
print "\n</tr>";
}
Thanks ahead of time for your thoughts and recipes :)
Grant