I am working on a menu page for a restaurant for which I use the following 3 tables:
CREATE TABLE IF NOT EXISTS `menu_categories` (
`menu_category_id` smallint(2) NOT NULL auto_increment,
`menu_category` varchar(255) default NULL,
PRIMARY KEY (`menu_category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `menu_groups` (
`menu_group_id` smallint(2) NOT NULL auto_increment,
`menu_category_id` smallint(2) NOT NULL,
`menu_group` varchar(255) default NULL,
PRIMARY KEY (`menu_group_id`),
FOREIGN KEY (`menu_category_id`) REFERENCES `menu_categories` (`menu_category_id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `menu_items` (
`menu_item_id` smallint(2) NOT NULL auto_increment,
`menu_group_id` smallint(2) NOT NULL,
`menu_item` varchar(255) default NULL,
`description_dut` text,
`description_eng` text,
`price` varchar(20) default NULL,
PRIMARY KEY (`menu_item_id`),
FOREIGN KEY (`menu_group_id`) REFERENCES `menu_groups` (`menu_group_id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Where the table menu_categories is representing the 5 main categories (Soups. Appetizers, Main Dishes etc), menu_groups the different groups in each category (e.a. Salads and Hot Appetizers in Appetizers) and menut_items the different dishes within a menu_group(e.a. Tempura Prawn and Pancake Duck in Hot Hot Appetizers).
In 3 of the 5 main categories there are more then 1 menu_groups so in the echo I need to group them by menu_group. I tried to do that the following way:
$category_id = filter_input(INPUT_GET, 'category_id', FILTER_SANITIZE_NUMBER_INT);
$qryMenu = " SELECT M.menu_group, C.menu_item, C.description_dut, C.description_eng, C.price
FROM menu_groups M
INNER JOIN menu_items C
ON M.menu_group_id = C.menu_group_id
WHERE menu_category_id = $category_id
GROUP BY menu_group;";
if ($result = $mysqli->query($qryMenu)) {
while ($row = $result->fetch_assoc()) {
echo "<dl>
<dt>{$row['menu_group']}</dt>
<dd>{$row['menu_item']}<span>€ {$row['price']}</span></dd>
<ul>
<li>{$row['description_dut']}</li>
<li>{$row['description_eng']}</li>
</ul>
</dl>";
}
}
But that is not the way to go. I think I need an nested echo but have no idea how to approach that?.
I hope this is a bit clear
Thank you in advance