Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

In need of assistance with SQL/PHP loops

$
0
0

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.

metrodb.png

 

 

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

Slo Down Wines

http://www.slodownwines.com/

Broken Dreams

Sexual Chocolate

 

 

Central Coast

Jackhammer

http://jackhammerwine.com

Pinot Noir

 

Happy Canyon of Santa Barbara

Cimarone Winery

http://www.cimarone.com/

3CV Bank

 

3CV Cilla’s Blend

 

Le Clos Secret

 

Gran Premio

 

3CV Estate Sauvignon Blanc

 

Dragonette Cellars

http://dragonettecellars.com/

GMS Rose

 

Sauvignon Blanc

 

 

Happy Canyon Vineyards

http://happycanyonvineyard.com/

Ten Goal

 

Merlot

http://happycanyonvineyard.com/

Piocho

 

 

Margerum Wine Company

 

Sybarite Sauvignon Blanc

 

Paso Robles

Spaceman Vineyards

 

Reserve Airspace

 

Santa Barbara County

Ampelos Cellars

 

Syrache - Syrah & Grenache

 

 

 

Margerum Wine Company

http://www.margerumwinecompany.com/

Chenin Blanc

 

M5

 

Riesling

 

Uber Reserve

 

 

 

Tercero

http://tercerowines.com/

Grenache

 

Grenache Blanc

 

The Climb

 

 

Santa Lucia Highlands

Jackhammer

http://jackhammerwine.com

Chardonnay

 

Santa Maria

Tyler Winery

 

Bien Nacido Pinot Noir

 

Sta Rita Hills

Ampelos Cellars

http://ampeloscellars.com/

Pinot Noir

 

Lambda Reserve

 

Rho Reserve

 

Viognier

 

 

Dragonette Cellars

http://dragonettecellars.com/

 

 

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.


Viewing all articles
Browse latest Browse all 13200

Trending Articles