Jump to content

** SOLVED ** Interesting MySQL SELECT query issue


criticman

Recommended Posts

[!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--][!--fonto:Arial Black--][span style=\"font-family:Arial Black\"][!--/fonto--]SOLVED - Thanks[!--fontc--][/span][!--/fontc--][!--sizec--][/span][!--/sizec--]

 

So I am working on a project for a company doing an online e-commerce site with a full product catalog.

 

I had things going just fine until they put some interesting requirements on me. This required restructuring of the MySQL table.

 

So, I now have an issue. I am working on the "browse products" page. I have no issue displaying categories, then subcategories, then listing all items under them. The issue is there are several item #'s for each set of item.

 

Items have different sizes, and unfortunately each size has its own item number.

 

I.E.

ONG76515-XL, ONG76515-L, ONG76515-S, ONG76515-M

 

What the client now wants (contrary to original request and I do not have time to redo the MySQL tables) is to only display ONE item number on the browse page per set of similar item #'s (basically, show size S and hide sizes M, L, XL until you get to the product detail page).

 

So, right now my query is thus:

 

SELECT * FROM ProductList WHERE cat = '$cat' AND subcat = '$subcat' ORDER BY brand, prodName, details ASC

 

Is there a somewhat efficient way to go about doing this within the SQL query? I would like it to be optimized to the query so that I am not creating tons of overhead by loading 100's of item #s and then hiding all but one per item # set using PHP.

 

Any help is more than appreciated. I am just stumped and in need of sleep. Project is due Monday AM.

Link to comment
Share on other sites

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM ProductList WHERE cat = '$cat' AND subcat = '$subcat' AND RIGHT(itemNumber,1)='S' ORDER BY brand, prodName, details ASC [!--sql2--][/div][!--sql3--]

Link to comment
Share on other sites

[!--quoteo(post=318395:date=Nov 14 2005, 12:13 PM:name=ryanlwh)--][div class=\'quotetop\']QUOTE(ryanlwh @ Nov 14 2005, 12:13 PM) 318395[/snapback][/div][div class=\'quotemain\'][!--quotec--]

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * FROM ProductList WHERE cat = '$cat' AND subcat = '$subcat' AND RIGHT(itemNumber,1)='S' ORDER BY brand, prodName, details ASC [!--sql2--][/div][!--sql3--]

 

Thanks. I posted this on several forums, same response on all. Not all item numbers follow that format, so I will have to restructure the table when I have the time. For now they will have to deal with what I have given them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.