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
https://forums.phpfreaks.com/topic/19027-pagnation-carrying-query-over/
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... ;)

Archived

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

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