SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Other Forums
 Other Topics
 How to query an Advanced Search Narrows Results
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jdsmith8
Starting Member

USA
11 Posts

Posted - 08/18/2014 :  18:30:27  Show Profile  Reply with Quote
I have a SQL Database table named LISTINGS and it has 8 columns that users can have added a 'Y' through checkboxes in a form previously. The 8 columns are named CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7 and CAT8 and all connect to the main LISTING_ID for each entered listing.

I want to have an advanced search form on the site that has the 8 fields (CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7 and CAT8) as options to check one or multiple and then displays the listings with those categories if those listings have Y in the field columns.

So if someone checks 5 out of the 8 categories like CAT1, CAT3, CAT4, CAT6 and CAT8 then submits the form it will check to see if any of the listings have 'Y' in each of those columns and if so display the queried results that do.

If a listing has more then no problem as long as the fields have 'Y' that are queried so a listing that had all 5 of the above fields with 'Y' in it plus say CAT7 with a 'Y' would still show in the results.

How can this be done? Would I have to make the form use say 8 letters as values (A, B, C, D, E, F, G and H) for each option and then a separate page for each possible query option like

if(IsChecked('checkbox','A,B,C,D,E,F,G,H'))
{
//do something ...
}

if(IsChecked('checkbox','A,B,C,D,E,F,G'))
{
//do something ...
}

if(IsChecked('checkbox','A,B,C,D,E,F'))
{
//do something ...
}
etc..

And would that not be virtually impossible with thousands of combinations going from only one field value checked for the advanced search up to all 8 checked?

Any help on this is greatly appreciated.
Thanks,
Jay

James Smith

gbritton
Flowing Fount of Yak Knowledge

1770 Posts

Posted - 08/19/2014 :  07:55:10  Show Profile  Reply with Quote
See this article: http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000