Member Avatar for Loi-se

I have a question about how to set up a faceted search function in PHP and SQL. I wonder how the result set should be filtered based on the selected facet values.
For example if I have a facet menu with 5 filter options how should I filter the results. Should I use one big query that I expand based on the selected faceted values with AND structures like this:
SELECT
FROM
WHERE
AND..... AND..... AND

Or is it better to have one initial query and start fitering based on the result set. Like for example you have an array with objects of the type you want, and you just iterate trough this collection and filter the objects based on the selected facet values? Which option is better?

And does anybody know a good website or forum post with more information on how to setup a filter function?

Member Avatar for diafol

Do as much filtering in the SQL as possible IMO. You retrieve unwanted records otherwise, which can take time + the time to filter in code. Double whammy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.