Hello

I was wondering, is the a better way of creating menus like this but maybes only using one query ?

CODE
# Groups
$sql = "select group_id, group_title from groups order by group_order asc";

foreach( $database->getRows($sql) as $group ) {
    
    # print menu
    
    # Categories
    $sql = "select category_id, category_title from categories where category_group = '" . $group["group_id"] . "' order by category_order asc";
    
    foreach( $database->getRows($sql) as $category ) {
        
        # print menu
        
        # Subcategories
        $sql = "select category_id, category_title from categories where category_parent = '" . $category["category_id"] . "' order by category_order asc";
        
        foreach( $database->getRows($sql) as $subcategory ) {
            # print menu
        }
    }
}


Group Table Structure

CODE
CREATE TABLE IF NOT EXISTS `groups` (
  `group_id` int(4) NOT NULL auto_increment,
  `group_title` varchar(200) NOT NULL,
  `group_description` text NOT NULL,
  `group_order` int(4) NOT NULL,
  KEY `group_id` (`group_id`)
) ENGINE=InnoDB;


Categories Table Structure

CODE
CREATE TABLE IF NOT EXISTS `categories` (
  `category_id` int(4) NOT NULL auto_increment,
  `category_title` varchar(255) NOT NULL,
  `category_description` varchar(255) NOT NULL,
  `category_order` int(4) NOT NULL,
  `category_parent` int(4) NOT NULL,
  `category_group` int(4) NOT NULL,
  KEY `category_id` (`category_id`)
) ENGINE=InnoDB;