Pawn Posted March 23, 2010 Share Posted March 23, 2010 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? Link to comment https://forums.phpfreaks.com/topic/196258-building-counters-from-paginated-search-results/ Share on other sites More sharing options...
andrewgauger Posted March 23, 2010 Share Posted March 23, 2010 $_SESSION parsing? Link to comment https://forums.phpfreaks.com/topic/196258-building-counters-from-paginated-search-results/#findComment-1030658 Share on other sites More sharing options...
Pawn Posted March 23, 2010 Author Share Posted March 23, 2010 I'm not sure I see how sessions would help in this scenario. At the moment as far as I can see my options are either to perform a bunch of extra queries to get the counts, or to grab the whole data set and perform the pagination logic in the PHP. Neither is hugely appealing. Link to comment https://forums.phpfreaks.com/topic/196258-building-counters-from-paginated-search-results/#findComment-1030696 Share on other sites More sharing options...
andrewgauger Posted March 23, 2010 Share Posted March 23, 2010 <?php $counters=array(); $counters["Literature"]=8; $counters["Fiction"]=4; foreach ($counters as $key => $value) { $_SESSION[$key]=$value; } ?> Although better to use a class, this demonstrates how you can use Session variables to accomplish this. Read this: http://www.php.net/manual/en/intro.session.php Link to comment https://forums.phpfreaks.com/topic/196258-building-counters-from-paginated-search-results/#findComment-1030799 Share on other sites More sharing options...
Pawn Posted March 25, 2010 Author Share Posted March 25, 2010 I still have no idea what you're talking about. Link to comment https://forums.phpfreaks.com/topic/196258-building-counters-from-paginated-search-results/#findComment-1031815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.