tags:

views:

40

answers:

1

Hi !

How can i get the number of each filter item in a seach?

Example... im doing a job/resumes portal... i seach a job title and i have some filters items like City, State , area and etc... How can i show the number of each filter in the select box example Contry: Brazil(22 results), USA(61 results)

Here a url with a sample: http://www.manager.com.br/resumes/resumes_result.php?&search_table=resumes&tipo_local=0&keyword=program&

Tkz Roberto

A: 

You should get acquainted with GROUP BY clause and count(*) aggregate function:

SELECT Country, count(*)
FROM items
GROUP BY Country;

And when you have absorbed the necessary minimum, take a look at useful extensions to the GROUP BY clause in MySQL, namely WITH ROLLUP.

newtover
tkz... ill check this... but its not "too much" to a mysql handling with a lot of options (as screenshot sample) to a search where a lot of people will be using?
Roberto
@Roberto: When you develop, you should adjust the database schema to the needs of the business. In any real-world application you will have queries that are complex and slow, but you should understand why they are slow. Sometimes it is rather easy to re-organize your data in a way, that querying them would not be killer to your system.
newtover
Thank you very much newtover ;)
Roberto