Jump to content

Group query results


vtroubled

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/70652-group-query-results/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/70652-group-query-results/#findComment-355078
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.