Solved

Querying a Query for Search Panel

Posted on 2014-11-26
4
75 Views
Last Modified: 2014-12-24
I don't even know what to "search" under on google to find the answer. I've tried a few things and the results don't have anything like I'm looking for, so I'll ask here.

You know those car dealership websites where they have you search for cars and then on the left is a search panel with a bunch of checkboxes. It shows there are:
Fords (22)
Hondas (13)

Then you can click just Hondas and it gets rid of the Fords and shows only the Hondas. And same with models, colors, etc. etc.

That's the type of search I want to do.

How does one do the query involved in that? Are they creating a main sql and using some kind of dataset and searching within that dataset? Or what exactly is happening with the query and data behind the scenes?

I don't need to know how to ajax the boxes and such, just how to handle that query. Those sites are pretty fast when returning data and I'd like to use best practices on this and not try to figure out what I think is going on. If you don't know, please don't respond, I'd prefer not to get guesses and would like an answer from someone who knows how to do it for certain.

thanks!
0
Comment
Question by:BobCSD
  • 2
4 Comments
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 200 total points
ID: 40467356
It's essentially a GROUP BY that goes something like this:

SELECT MakeName, COUNT(Make) as the_count
FROM YourTable
WHERE -- whatever the user selects
GROUP BY MakeName

Open in new window


Then if the user clicks on one it'll show the details like this:
SELECT yabba, dabba, doo
FROM cars
WHERE MakeName='{whatever the user clicked on}'

Open in new window

For a frienly tutorial on grouping visit SQL Server GROUP BY Solutions
0
 
LVL 1

Author Comment

by:BobCSD
ID: 40469328
I understand grouping, I guess I just thought as quick as those search panels come up and when the user clicks the checkboxes the results come up quickly, I thought maybe there was something quick going on. Like maybe you start with a dataset of everything, and then you query against the dataset or something.

I can do all of the above individually as queries, I just figured there was some magic I was missing to make it streamlined and quick. So nothing special is going on?

Every single checkbox group is queried for the search panel for the count?
then when you click a checkbox every single click rebuilds the query and displays the results?
and so on?

that part is easy to do. But it just seems so tedious to hit the database that many times so I thought something else might be going on that I didn't know about.

thanks!
0
 
LVL 8

Accepted Solution

by:
Ashutosh Vyas earned 300 total points
ID: 40475339
Load all your data at the beginning into a DataTable and put that Datatable as the source for your gridview (I am assuming you are displaying your data in the gridview).

When the checkboxes are checked, construct the filters for datatable and rebind.
Something like

   
 dt.DefaultView.RowFilter = "MakeName= '" + filterText + "'";
    gvList.DataSource = dt.DefaultView;
    gvList.DataBind();

Open in new window

0
 
LVL 1

Author Comment

by:BobCSD
ID: 40477867
Ashutosh,

thanks! that's more in line with what I thought might be happening. I'll try it out within the next week or so and let you know if I have further questions. thanks so much!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now