I have some data in a database and its getting outputted with an ORDER BY category and I was wondering how do I only display the category once?
$SQL = mysql_query("SELECT id,name,category FROM table ORDER BY category,id");
So my script iterates through the table and sorts all the items by the category name.
I want to be able to display the category name once so then the rest of the values can fall within that category
I currently have something like this
while($r = mysql_fetch_array($SQL){
$name = $r['name'];
$category = $r['category'];
echo $category; //I want to be able to echo this once
echo $name; // this will be echoed many times depending on the category this falls into
}
1 Answer