I am building a web application connected to MySQL database that is supposed to work like an e-shop. User should be able to filter products, but I want to display the number of results that would be added to result with each choice, like in this picture:
This should work across all parameters (like all display, battery or price options), as well as showing the total number of results with current filter, that would change each time the user changes something in the filter.
I know this is a common feature, but I need to get the general idea how this works. These are my ideas:
- there might be a tool that periodically calculates and caches the number of results for each possible combination in the background.
- or are the
SELECT COUNT(*) FROM database WHERE <conditions>queries running each time the user checks a field in the filter, for each possible combination? But that would take too long, right?
I would be grateful for any ideas, especially article links or anything related to this topic.