I'm designing a website for a wine wholesaler that needs to be able to update and display their product catalog in a certain specific way. The site in development is at www.metrocellars.com/new/
Let me first begin by outlining the database tables in use:
- location - a table of 6 records, the broader breakdown of geographic location (Brazil, California, etc.) These rows are used in the navigation menu, and each location has many "regions" referencing them.
- region - the more specific area of origin of each product (wine). Each "Region" references one of the 6 broader "Locations".
- product - The meat of the db, each Product record references a Producer/Winery (PID), a specific Region (RID - which also references a broader Location), and a specific Varietal (VID - Wine type/color). The left part of the image below shows part of the Product table.
- winery - This table holds records of each Winery/Producer referenced by PID in Product table.
- varietals - This table lists each type of wine, (Pinot, Merlot, etc) referenced by VID in the Product table.
On the right side of the above image, I included a visual of the relevant tables with FK relation lines. I haven't figured out which ON DELETE/UPDATE to use, as I got errors a couple times from child rows as I was assigning indexes/keys. I'm a little rusty with the SQL at the moment.
Using this model, I need to be able to output the data to a wine list page, but I am having problems putting together the right queries and loops to list the data in the requested format. Here is an example of what the page content should look like when the 'region' California (LID = 2) is clicked on the nav menu.
California
Broken Dreams
Sexual Chocolate
Central Coast
Pinot Noir
Happy Canyon of Santa Barbara
3CV Bank
3CV Cilla’s Blend
Le Clos Secret
Gran Premio
3CV Estate Sauvignon Blanc
GMS Rose
Sauvignon Blanc
http://happycanyonvineyard.com/
Ten Goal
Merlot
http://happycanyonvineyard.com/
Piocho
Sybarite Sauvignon Blanc
Paso Robles
Reserve Airspace
Santa Barbara County
Syrache - Syrah & Grenache
http://www.margerumwinecompany.com/
Chenin Blanc
M5
Riesling
Uber Reserve
Grenache
Grenache Blanc
The Climb
Santa Lucia Highlands
Chardonnay
Santa Maria
Bien Nacido Pinot Noir
Sta Rita Hills
Pinot Noir
Lambda Reserve
Rho Reserve
Viognier
In the above list, each heading is a record of each "Region" with the same LID as California in the Location table. LID = 2, so I need to list each Region within California, and within each of those listings, list each Wine that has the same RID as that Region, but grouped by their respective Wineries. Basically, there are a few Wineries that have products (child rows I believe) with differing Regions of origin. So, there are products that can have the same PID, but different RID.
You can get an idea of the format from the above example. My problem is, is how would I nest the loops and queries, and what joins would be necessary? Any and all help is a godsend. This has been quite a headache.