SharkBait Posted August 29, 2006 Share Posted August 29, 2006 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'dIf 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 More sharing options...
AndyB Posted August 29, 2006 Share Posted August 29, 2006 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 https://forums.phpfreaks.com/topic/19027-pagnation-carrying-query-over/#findComment-82348 Share on other sites More sharing options...
HeyRay2 Posted August 29, 2006 Share Posted August 29, 2006 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 asa hidden form element, and each page link a form submission button with a different value (the page number).[code]<?phpecho '<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 https://forums.phpfreaks.com/topic/19027-pagnation-carrying-query-over/#findComment-82383 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.