I've created a mysql table that includes these rows & values:
category | item_name
=======================
Dinner | Lobster
Dinner | Pizza
Lunch | Sandwich
Lunch | Soup
Lunch | Salad
-------------------------
I then query the database, the result is placed in an array "$menu_selected". I loop through "$menu_selected" to display the results.
foreach($menu_selected as $m):
echo $category = $m->category . "<br>";
echo $item_name = $m->item_name . "<br><br>";
endforeach;
Output:
Dinner
Lobster
Dinner
Pizza
Lunch
Sandwich
Lunch
Soup
Lunch
Salad
How can I filter the categories in PHP so it doesn't echo each category only the first instance of category? The category row value isn't always going to be "Dinner" or "Lunch", I want to be able to echo the category without comparing it to a constant like if($category =='Dinner'){}. I've spend a week researching and can't figure it out. Anyone's help would be greatly appreciated.
I want the output to look like this:
**Dinner**
Lobster
Pizza
Sandwich
**Lunch**
Sandwich
Soup
Salad