skaterdav85 Posted April 2, 2009 Share Posted April 2, 2009 so i have some data in my mysql database:name | type----------------playstation | ToyBlouse | Clothingapple | Foodnintendo | Toypants | Clothinghot dog | FoodI want to output it in groups so that on my page it looks something like this:ToyplaystationnintendoClothingBlousepantsFoodapplehot dogthis is my php code so far, but it just outputs each row in the table. But I only want one heading for each type. $query = "SELECT type, name FROM products ORDER BY type DESC"; $result = mysql_query($query) or die(mysql_error());// Print out resultwhile($row = mysql_fetch_array($result)){ echo "<b>".$row['type']."</b><br/>"; echo $row['name']; echo "<br />";}Anyone know how to accomplish this? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 3, 2009 Share Posted April 3, 2009 Have a variable that keeps track of the last heading you printed, and when the next record has a heading different from the value in that variable, print the heading and save the new value. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.