I’m creating eBay style search panes that allow users to narrow their results set by certain criteria. For example:
Tags
Literature (8)
Fiction (4)
English (4)
American (3)
Non-fiction (2)
The number of results which have that property is in brackets. Initially, I built the counters by putting this code in my display results loop:
if(isset($tags[$row['tags']])) {
$tags[$row['tags']]++;
} else {
$tags[$row['tags']] = 1;
}
Then I paginated my results and that stopped working – the query only returns enough data for the page you are on, so the counters only represent the results on that page.
Can anyone suggest another approach?
You’ll have to run a second query for
tag, COUNT(*) in <table> GROUP BY tagto get total numbers for each tag.edit:
Check this out. This is a new one by me, but it looks like what you want.
Start your query with
SELECT SQL_CALC_FOUND_ROWS, then follow up your query withSELECT FOUND_ROWS();