I'm working on a site that is a menu-based food ordering site. I have the following tables (relevant fields listed):
calendar (stores all events and event info)
- event_id
- menu_id
menus (stores all available menus)
- menu_id
menu_items (stores all available menu items)
- item_id
menu_lists (stores which menu items are associated with which each menu)
- menu_id
- item_id
orders (stores information about each order placed)
- event_id
order_items (stores all items placed for each order)
- order_id
- item_id
What I need to show is a table that contains each day, and the total of each item ordered for that day (32 of item 108, 17 of item 112, etc.). I then need to show each event that day, and an item by item breakdown for that event (2 of item 108, 0 of item 112, etc.).
Currently what I'm doing is running a query that pulls all the days and events for the given time period (by default this week). I then store all the event info in an array, then loop through that array and for each day and each event for that day, I'm running a query to pull the needed menu item info. For the most part this way works, but it seems terribly slow and inefficient.
As if that isn't enough, I also need to show the number of menu items that are for new orders (customers that haven't ordered before), and return orders (customer who have > 1 order).
The attached image illustrates exactly what I need the end result to be.
Any ideas would be most appreciated. TIA.