You are here:  » Results Per Page: xx

Support Forum



Results Per Page: xx

Submitted by Capricorn on Tue, 2012-09-25 18:16 in

Hi David

With the new SearchResultsGridList script, we can now have a link to "Grid View, or List View"

Is it possible to also add a link to something like: "Display per page: 10 - 20 - 30 "

I know that the default results per page is set on the config.php script, but I wonder if the searchresults.php can be mod to change the default number.

Thanks.

Submitted by support on Wed, 2012-09-26 08:22

Hi Capricorn,

Sure! To make these instructions generic rather than specific to the grid/list view mod, in search.php look for the following code at line 10:

  $sort = (isset($_GET["sort"])?$_GET["sort"]:"relevance");

...and REPLACE with:

  $sort = (isset($_GET["sort"])?$_GET["sort"]:"relevance");
  $show = (isset($_GET["show"])?$_GET["show"]:$config_resultsPerPage);
  $config_resultsPerPage = $show;

Next look for the following code at line 296:

      $sortHREF .= "sort=";

...and REPLACE with:

      $sortHREF .= "show=".$show."&";
      $sortHREF .= "sort=";

And then the following code at line 375:

    require("html/navigation.php");

...and REPLACE with:

    $sort .= "&show=".$show;
    require("html/navigation.php");

Finally, to add the links as a drop-down form which keeps it nice and tidy, with auto-submit (or submit button if noscript), look for where the H3 banner is set by the code around line 313 beginning:

      $banner["h3"] =

...and then insert immediately AFTER that line:

      $showOptions = array(10,20,30);
      $showForm = "<form method='GET' style='display:inline;'>";
      $showForm .= "&nbsp;Show: ";
      $showForm .= "<input type='hidden' name='q' value='".htmlentities($q)."' />";
      $showForm .= "<input type='hidden' name='sort' value='".htmlentities($sort)."' />";
      $showForm .= "<select name='show' onChange='this.form.submit();'>";
      foreach($showOptions as $v)
      {
        $selected = (($show == $v)?"selected='selected'":"");
        $showForm .= "<option value='".$v."' ".$selected.">".$v."</option>";
      }
      $showForm .= "</select>";
      $showForm .= "<noscript><input type='submit' value='Change' ></noscript>";
      $showForm .= "</form>";
      $banner["h3"] .= $showForm;

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Capricorn on Wed, 2012-09-26 22:08

Hi David,

The code works perfect in "List View", but when I switch to "Grid View", it defaults to 10, and even clicking on Show: 10-20-30, it will show the number of products selected, but in "List View" only.

It will not show more than 10 products in "Grid View".

Maybe the code needs another little tweak?

Thanks.

Submitted by Capricorn on Thu, 2012-09-27 00:18

David,

I found a little bug in that code.

I thought the code was working perfect in "List View" but, I just discovered that once the "Grid View" is clicked, not only the "Grid View" don't display as a grid, but then the "List View" will look ok, but now none of these links "Previous | 1 2 3 4 5 6 7 8 9 | Next" will work anymore, because this is the error I get on the top of the page:

==========================================================
[SELECT SQL_CALC_FOUND_ROWS * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `pt_products` WHERE merchant = 'mymerchantname' GROUP BY name LIMIT 0,][You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
==========================================================

Product search results for merchant:mymerchantname: (no results found)

==========================================================

Thanks.

Submitted by support on Thu, 2012-09-27 08:26

Hi Capricorn,

My apologies I forget to mention that the view parameter would need to be added to your version of the drop down form - have a go with:

      $showOptions = array(10,20,30);
      $showForm = "<form method='GET' style='display:inline;'>";
      $showForm .= "&nbsp;Show: ";
      $showForm .= "<input type='hidden' name='q' value='".htmlentities($q)."' />";
      $showForm .= "<input type='hidden' name='sort' value='".htmlentities($sort)."' />";
      $showForm .= "<input type='hidden' name='view' value='".htmlentities($view)."' />";
      $showForm .= "<select name='show' onChange='this.form.submit();'>";
      foreach($showOptions as $v)
      {
        $selected = (($show == $v)?"selected='selected'":"");
        $showForm .= "<option value='".$v."' ".$selected.">".$v."</option>";
      }
      $showForm .= "</select>";
      $showForm .= "<noscript><input type='submit' value='Change' ></noscript>";
      $showForm .= "</form>";
      $banner["h3"] .= $showForm;

Also in place of this modification:

  $config_resultsPerPage = (isset($_GET["show"])?$_GET["show"]:$config_resultsPerPage);

use:

  $config_resultsPerPage = (isset($_GET["show"] && $_GET["show"])?$_GET["show"]:$config_resultsPerPage);

That will ensure that $config_resultsPerPage is never set to an empty value which was the cause of your SQL error...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Capricorn on Thu, 2012-09-27 18:24

David,

I think there is something wrong in this line:

$config_resultsPerPage = (isset($_GET["show"] && $_GET["show"])?$_GET["show"]:$config_resultsPerPage);

After I add that line I get this error:

Parse error: syntax error, unexpected '&&' (T_BOOLEAN_AND), expecting ',' or ')' in F:\xampp\htdocs\testshop\search.php on line 11

Without that line, the "Grid View" and the "List View" work fine, but only the default number of products (10) show up, even after clicking 20 or 30, just 10 show up.

Submitted by support on Thu, 2012-09-27 18:42

Hi Capricorn,

There was a missing bracket - have a go with:

 $config_resultsPerPage = ((isset($_GET["show"]) && $_GET["show"])?$_GET["show"]:$config_resultsPerPage);

Cheers,
David.
--
PriceTapestry.com

Submitted by Capricorn on Thu, 2012-09-27 19:32

David,

The missing bracket fixed all those problems, but now I noticed one more little issue.

Everything is working fine with the selection of 10-20-30 for the "Grid View" and the "List View" when I select any of those numbers from the drop box, but if I click any of the links on the "Previous | 1 2 3 4 5 6 7 8 9 | Next" navigation line, the setting on the drop box don't remember the last selection and the next page just shows the default 10 products at the time.

For example, after selecting 30, I get this:

Product search results for merchant:mymerchantname: (showing 1 to 30 of 189)

And if I then click "Next" or any of the numbers on the navigation line, it will show the next 10 products instead of the next 30, like this:

Product search results for merchant:mymerchantname: (showing 11 to 20 of 189)

I think it have something to do with the drop box reverting to the default of 10, instead of remembering the last number selected.

David, I'm sorry to bother you again with this post, but I think this is the last bug I found on the script.

Thanks.

Submitted by support on Fri, 2012-09-28 06:13

Hi Capricorn,

I missed out the line the set $show when documenting the original modification description above; in your modified version of search.php where you now have:

  $config_resultsPerPage = (isset($_GET["show"])?$_GET["show"]:$config_resultsPerPage);

...REPLACE that with:

  $show = (isset($_GET["show"])?$_GET["show"]:$config_resultsPerPage);
  $config_resultsPerPage = $show;

Everything will fall into place then, including the 10-20-30 drop-down showing the current value rather than defaulting to 10 every time...

Cheers,
David.
--
PriceTapestry.com

Submitted by Capricorn on Fri, 2012-09-28 16:15

Thank You very much, David!

Everything is working fine now.