You are here:  » Pagination at comparison table


Pagination at comparison table

Submitted by Aslex on Sat, 2011-01-22 17:59 in

Hi David,

another question, another thread - I hope this is ok ;-)

A pagination at the product site (the comparison table) would be nice - list 10 products at the same time and then show a link with "more products" or better links to product-site1, product-site2 and so on.

Thank you and best regards,
Alex

Submitted by support on Mon, 2011-01-24 15:43

Hi Alex,

It's reasonably straight forward to add pagination into your products page prices table. In your html/prices.php, look for the following code around line 9:

    <?php foreach($prices["products"] as $product): ?>

...and REPLACE that with:

    <?php foreach($prices["products"] as $k => $product): ?>
    <?php
    $pricesPerPage = 10;
    $pricesPage = (isset($_GET["page"])?$_GET["page"]:1);
    if ($k < ($pricesPerPage * ($pricesPage-1))) continue;
    if ($k > (($pricesPerPage * $pricesPage))-1) break;
    ?>

Next, look for where the prices table is closed by this code at line 19:

  </table>

...and REPLACE that with:

  </table>
  <?php
  if ($k > ($pricesPerPage)) print " <a href='?page=".($pricesPage - 1)."'>Previous Page</a>";
  if ($k < (count($prices["products"])-1)) print " <a href='?page=".($pricesPage + 1)."'>More Prices...</a>";
  ?>

This will give you "More Prices..." and "Previous Page" links where there are more results than $pricesPerPage as set in the first part of the modification...

Cheers,
David.
--
PriceTapestry.com

Submitted by Aslex on Mon, 2011-01-24 19:51

Works fine! Thank you... again ;-)

Best regards,
Alex

Submitted by marco.saiu on Wed, 2011-08-03 01:22

Hello David,

i have same problem and i have integrate your script but the link in the bottom not have $q values...

For example i see this page ../products.php?q=ACCESSORI+Cinture&all=1 (in this moment have 88 prices) i dispaly 10 prices and in the bottom 2 link Previus Page and More Prices but the value of this link not save $q and if i click i return to ../products.php (blank page)...

Have any solutions ???

Thank's

Submitted by support on Wed, 2011-08-03 08:22

Hi Marco,

Here's the final replacement from above for use without rewrite:

  </table>
  <?php
  if ($k > ($pricesPerPage-1)) print " <a href='?q=".urlencode($q)."&page=".($pricesPage - 1)."'>Previous Page</a>";
  if ($k < (count($prices["products"])-1)) print " <a href='?q=".urlencode($q)."&page=".($pricesPage + 1)."'>More Prices...</a>";
  ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by paullas on Sun, 2021-12-12 22:16

Hi David

I would like to add to the below if that is ok.

I am making individual pages for example products.php and using the following code:

<?php
  $_GET
["q"] = "category:Football-Gifts";
  require(
"searchcode.php");
  require(
"html/searchresults.php");
?>

The problem i have is it is displaying the amount of products that is listed in the config.php file which is 50.

Can i ask how do i add a next a previous option on the page and have it so it only lists 15 products then the custom clicks on next and it lists the next 15 products and so on.

{link saved}

Many thanks

Paul

Submitted by support on Mon, 2021-12-13 10:03

Hi Paul,

You could override the results per page at the top of searchcode.php e.g.

  $config_resultsPerPage = 15;

Then to add the pagination just call in html/navigation.php after the search results e.g.

<?php
  $_GET
["q"] = "category:Football-Gifts";
  require(
"searchcode.php");
  require(
"html/searchresults.php");
  require(
"html/navigation.php");
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by paullas on Mon, 2021-12-13 11:31

spot on thank you.