Building counters from paginated search results...?
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 {
$t开发者_开发知识库ags[$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 tag
to 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 with SELECT FOUND_ROWS();
SELECT COUNT(*) FROM books WHERE tagid=$tagid
This would require another query however. Please supply more info about your pagination methods.
精彩评论