Re: bags o beans - filtering rows/array by value of an aggregated attribute
| From: | John Holmes | Date: | Fri, 06 Aug 2004 02:18:04 +0000 |
| Subject: | Re: bags o beans - filtering rows/array by value of an aggregated attribute | ||
| References: | 1 2 3 4 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35609@lists.php.net to get a copy of this message | ||
Grant Listhandle wrote:
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 :) GrantAre we doing your homework for you? Why not just do this in your query? SELECT bean_type, sum(number_o_beans)AS sum_beans FROM bags_o_beans GROUP BY bean_type HAVING sum_beans > 1000000 -- John Holmes php|architect - The magazine for PHP professionals - http://www.phparch.com