Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Interesting MySQL Query Issue - In need of help ASAP - Thanks
Old 11-13-2005, 04:19 AM Interesting MySQL Query Issue - In need of help ASAP - Thanks
Junior Talker

Posts: 4
Trades: 0
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:

Code:
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.
__________________
-Criticman
MCP, A+, Member IWA, Member HWG
9 yrs professional experience

Last edited by criticman; 11-13-2005 at 05:52 PM..
criticman is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-13-2005, 08:08 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,526
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
if the structure of the product code is always, refno-size then using this should work
Code:
 select fieldlist from table group by left(prod_code,instr(prod_code,'-')) ;
It will use the first one found as the group so the small size "-S" will have to appear first in the row order of the table

or if the -s can be out of sequence
Code:
select fieldlist from table where right(prod_code,length(prod_code) - instr(prod_code,'-')) = 's' ;
Might be better.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-13-2005, 05:46 PM
Junior Talker

Posts: 4
Trades: 0
Yeah, since not every item is -S -M -L or anything like this, I think I am going to just have to restructure the database.
__________________
-Criticman
MCP, A+, Member IWA, Member HWG
9 yrs professional experience

Last edited by criticman; 11-13-2005 at 05:53 PM..
criticman is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Interesting MySQL Query Issue - In need of help ASAP - Thanks
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21529 seconds with 12 queries