Jump to content


Pagnation - Carrying Query over

  • Please log in to reply
2 replies to this topic

#1 SharkBait

  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 29 August 2006 - 03:53 PM

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.

#2 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 29 August 2006 - 05:51 PM

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.

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

Legend has it that reading the manual never killed anyone.
My site

#3 HeyRay2

  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 29 August 2006 - 06:57 PM

How are you submitting your search form? POST or GET?

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


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

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


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


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>';


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


$current_page = $_POST['newpage'];


good luck... ;)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users