vtroubled Posted September 25, 2007 Share Posted September 25, 2007 Could anyone help someone who normally works with Cold Fusion and a complete novice in PHP, group together the results from a mysql query. I have a table of news stories that need to be grouped together under the product they refer too, so I want to display all the stories for PRODUCT A together and so forth. I've tried using the GROUP BY in the query but that only displays the first story. Any help or point in the right direction would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/70652-group-query-results/ Share on other sites More sharing options...
rarebit Posted September 25, 2007 Share Posted September 25, 2007 Use 'order' and a 'where' Quote Link to comment https://forums.phpfreaks.com/topic/70652-group-query-results/#findComment-355077 Share on other sites More sharing options...
cooldude832 Posted September 25, 2007 Share Posted September 25, 2007 group by can be tricky to work wiht, what is best is to do this <?php $q = "Select fields from `table` where this = that Order by Categroy"; $r = mysql_query($q) or die(mysql_error()); $cat = ""; while($row = mysql_fetch_array($r){ if($row['Category'] != $cat){ echo $row['Category']; } //Display data $cat = $row['Category']; } ?> that is the general idea if u got a question ask Quote Link to comment https://forums.phpfreaks.com/topic/70652-group-query-results/#findComment-355078 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.