ckpicker Posted April 19, 2009 Share Posted April 19, 2009 I've got a MySQL table called Locations with the following structure: ID, Region, State, Retailer. Given a region (Ie: Midwest) I would like to output my results by state by looping through my result set. Ex: Arkansas: Retailer 1 Retailer 2 Retailer 3 California: Retailer 1 Retailer 2 etc... Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/154789-php-grouping/ Share on other sites More sharing options...
ckpicker Posted April 19, 2009 Author Share Posted April 19, 2009 Not sure why this was moved to the MySQL forum. I'm looking for a way to loop through the result set in PHP... Quote Link to comment https://forums.phpfreaks.com/topic/154789-php-grouping/#findComment-813999 Share on other sites More sharing options...
Maq Posted April 19, 2009 Share Posted April 19, 2009 Not sure why this was moved to the MySQL forum. I'm looking for a way to loop through the result set in PHP... Cause that's how you would extract it from your database, using GROUP BY. Quote Link to comment https://forums.phpfreaks.com/topic/154789-php-grouping/#findComment-814005 Share on other sites More sharing options...
ckpicker Posted April 19, 2009 Author Share Posted April 19, 2009 Not sure why this was moved to the MySQL forum. I'm looking for a way to loop through the result set in PHP... Cause that's how you would extract it from your database, using GROUP BY. But I still want the invidual records to display. Won't a 'group by' query consolidate all the rows down to one? Quote Link to comment https://forums.phpfreaks.com/topic/154789-php-grouping/#findComment-814007 Share on other sites More sharing options...
ckpicker Posted April 19, 2009 Author Share Posted April 19, 2009 This is exactly what I was looking for: http://www.garfieldtech.com/blog/php-group-by Hopefully this will help someone else who is looking to group items in PHP. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/154789-php-grouping/#findComment-814024 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.