Jump to content

Pagnation - Carrying Query over


SharkBait

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.
Link to comment
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]
Link to comment
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... ;)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.