minimized queries for menu, nesting logic in php