Jump to content

Archived

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

SharkBait

Pagnation - Carrying Query over

Recommended Posts

My pagnation works great.. except if I use a search query and it is more than 1 page big.

It displayed the pages in the pagenation part right but if you click on one of the numbers it forgets the query it was looking at and just displays the data as if the query was never done.

What is the best way for having it 'remember' the query?  The query is a simple form text box that is $_POST'd

If needed I can post the lengthly pagnation code I have.

Share this post


Link to post
Share on other sites
Abstract relevant parameters for the search and pass them along with the links to previous/next pages in the previous/next URL works for me.

[code]<a href="show_stuff.php?page=$page&this=$var1&that=$var2&the_other=&$var3">next</a>[/code]

Share this post


Link to post
Share on other sites
How are you submitting your search form? POST or GET?

If using the GET method, can append the [b]$_SERVER['QUERY_STRING'][/b] variable to each pagination link, which contains your URL query:

[code]
<?php

$link = "http://www.mysite.com/search.php";

// add the query string to your pagination code for each link
$link = $link ."?". $_SERVER['QUERY_STRING'];

?>
[/code]

If you are using POST, you'll need to create a form with each [b]$_POST[/b] value echoed as
a hidden form element, and each page link a form submission button with a different value (the page number).

[code]
<?php

echo '<form name="next_search_page" action="search.php" method="POST">';

foreach( $_POST as $key=>$value ){
  echo '<input type="hidden" name="'.$key.'" value="'.$value.'" />';
}

// ... print your page links as form buttons ($pages for example)

foreach ( $pages as $page ){
  echo '<input type="submit" name="newpage" value="'.$page.'" />';
}

echo '</form>';

?>
[/code]

then you can determine which page was clicked on with the following code:

[code]
<?php

$current_page = $_POST['newpage'];

?>
[/code]

good luck... ;)

Share this post


Link to post
Share on other sites

×

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.