supaflyfrank Posted August 21, 2007 Share Posted August 21, 2007 Is there a way to run a specific query depending on a value received during the query. For example. I have two types of products. Regular and Packs. Regular is just a single item and packs are a group of different items. Now on my product listing page I want to display all my different types or products. My regular products will basically show image, mini description and price. On my packs I want to display image,mini description, price and a list of products that is included in the pack. But I want the list of products separate from the mini descriptions because its contents can be changed. So I am guessing in my table I need a way to determine if a product is regular or a pack. Therefore I basically have a True/False statement to determine if which type or product it is. The problem is I dont want to run an additional query trying to find all the items in a pack if the current product I am displaying isnt a pack. But at the same time when the query runs their is a chance that the product can be a pack. But this wont be determined until runtime. So I am wondering if their is any runtime query conditional statement that can run a single specific query depending on the product type as in If producttype == "Regular" Get Price, MiniDescription and Images elseif producttype == "Pack" Get Price,MiniDescription and Images Now I understand that it would be EXTREMELY easy if I just ran one query and then while displaying the item run another query but I wanted to avoid that if possible. So any suggestions would be great. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 21, 2007 Share Posted August 21, 2007 You can do it, but not entirely in MySQL without stored procedures. Quote Link to comment Share on other sites More sharing options...
Illusion Posted August 22, 2007 Share Posted August 22, 2007 select Price,IF(producttype="Regular",Description,Minidescription) Desc,Images from table; as long as u have only two states likes Regular(TRUE),pack or any other(FALSE). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.