I have a classifieds website, and it is using MySQL as a database.
My goal is to show the number of private, company and total ads in the db with the search-term entered in a text-input inside the form!
The Problem:
There are two types of ads: Private, and Company.
The user may specify which to display, or both, so thats three options.
On the website, after displaying the search results, I want to show the user THREE tabs: All ads, Private ads, Company ads.
I have a field in every record in MySQL which contains the value of either Private or Company.
I know of a way to display the number of private ads, company ads and TOTAL ads but it requires multiple queries.
For example, if the user CHECKS the PRIVATE ONLY check-box then only private ads are searched, but I won’t know how many company ads there are until I make a new query, where I search also for company ads. Then add them, and I have also the total nr of ads.
Just wonder if you know of a good way, to maybe get rid of the extra query?
Thanks
You could use a ROLLUP:
So with four Company and one Private ad you would see: