Jump to content

Building counters from paginated search results


Pawn

Recommended Posts

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?

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.

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.