SV: [PHP-DB] bags o beans - filtering rows/array by value of an aggregated attribute
Hi, Mysql_fetch_row() fetches an enumerated array, so it should be: If ($row[1] 100) while ($row = @ mysql_fetch_row($result)) { foreach($row as $data) if ({sum(number_o_beans)} (100)) if($row['total_number_of_beans']) 100) print \n\ttd {$data} /td; print \n/tr; } Thanks ahead of time for your thoughts and recipes :) Grant -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php !DSPAM:4112b26a148642019194572! -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] bags o beans - filtering rows/array by value of an aggregated attribute
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)} (100)) print \n\ttd {$data} /td; print \n/tr; } Thanks ahead of time for your thoughts and recipes :) Grant -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] bags o beans - filtering rows/array by value of an aggregated attribute
On Thu, 5 Aug 2004 17:26:05 -0500, Grant Listhandle [EMAIL PROTECTED] 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 Use a column alias: SELECT bean_type, sum(number_o_beans) AS total_number_of_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)} (100)) if($row['total_number_of_beans']) 100) print \n\ttd {$data} /td; print \n/tr; } Thanks ahead of time for your thoughts and recipes :) Grant -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php !DSPAM:4112b26a148642019194572! -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] bags o beans - filtering rows/array by value of an aggregated attribute
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)} (100)) print \n\ttd {$data} /td; print \n/tr; } Thanks ahead of time for your thoughts and recipes :) Grant Are 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 100 -- John Holmes php|architect - The magazine for PHP professionals - http://www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php