bruce080 Posted July 22, 2009 Share Posted July 22, 2009 I have a search tool that allows filtering by a couple of different categories. You select a value from a dropdown menu and it will filter the results to only show that specific product or system that was chosen. I also have pagination set up so that it will only display 20 documents per page but it will not repost the variables that were used for the filter. Is there a simple way to resubmit the current filter variables with another variable for page number? Thanks in advance for your help, Steven Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/ Share on other sites More sharing options...
WolfRage Posted July 22, 2009 Share Posted July 22, 2009 Going to need to see some code in order to tell you the best solution for your issue. Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880370 Share on other sites More sharing options...
ignace Posted July 22, 2009 Share Posted July 22, 2009 Make sure your query part never gets removed from the url: Change from: <a href="page.php"> To: <a href="page.php<?php print $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '';?>"> Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880377 Share on other sites More sharing options...
jcrew Posted July 22, 2009 Share Posted July 22, 2009 Just make sure the variables are on each page. ?category=apples&color=red&page=3 Blue being what they selected (SELECT * FROM harvest WHERE category='$_GET[category]' AND color='$_GET' LIMIT $x,$y). $x and $y being the limits determined by $_GET . Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880403 Share on other sites More sharing options...
bruce080 Posted July 22, 2009 Author Share Posted July 22, 2009 Oh great, I think that $_SERVER['QUERY_STRING'] is what I was looking for. That will make it a lot easier than my nested if statements... haha, I'm worthless. Anyway, I tried this code: echo "<dd class=\"next\"><a href=\"cc-nse-search.php<?php print $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : '';?>\"></dd>"; and it gave me this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Anyone care to enlighten me on what exactly that piece of code is supposed to be doing? In the meantime I'm going to try and incorporate QUERY_STRING into my code. Thanks for the help guys Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880426 Share on other sites More sharing options...
haku Posted July 22, 2009 Share Posted July 22, 2009 You are already in php (it's an echo statement', and you are trying to open new php tags. That doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880432 Share on other sites More sharing options...
bruce080 Posted July 22, 2009 Author Share Posted July 22, 2009 Great, I solved the problem. Here is the code that I am using to create a link to the next page in my search. echo "<dd class=\"next\"><a href=\"cc-nse-search.php"; print ($_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] . "&pageno=$next" : ''); echo "\">next</a></dd>"; Thanks, Steven Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880473 Share on other sites More sharing options...
bruce080 Posted July 22, 2009 Author Share Posted July 22, 2009 Wait, no, that didn't quite solve it either. How do I handle the $pageno variable. If I have: ?category=apples&color=red&pageno=3 and I want to make a link to the next page, how do I remove the pageno=3 variable and replace it with pageno=4? Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880480 Share on other sites More sharing options...
haku Posted July 22, 2009 Share Posted July 22, 2009 $next = $next + 1; Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880486 Share on other sites More sharing options...
bruce080 Posted July 22, 2009 Author Share Posted July 22, 2009 Sorry, I might have phrased that poorly. I know how to increment the page numbers, but I don't know how to change a variable when creating the link If my current QUERY_STRING is: ?category=apples&color=red&pageno=3 my code will just add a variable and create this new QUERY_STRING: ?category=apples&color=red&pageno=3&pageno=4 Is it possible to replace or change the original $pageno variable from the string so that I don't keep adding to it? Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880492 Share on other sites More sharing options...
jcrew Posted July 22, 2009 Share Posted July 22, 2009 Sorry, I might have phrased that poorly. I know how to increment the page numbers, but I don't know how to change a variable when creating the link If my current QUERY_STRING is: ?category=apples&color=red&pageno=3 my code will just add a variable and create this new QUERY_STRING: ?category=apples&color=red&pageno=3&pageno=4 Is it possible to replace or change the original $pageno variable from the string so that I don't keep adding to it? Yeah, just set $_GET[pageno] = $_GET[pageno] + 1; Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880507 Share on other sites More sharing options...
bruce080 Posted July 22, 2009 Author Share Posted July 22, 2009 You're right, setting $_GET[pageno]=4 will change the pageno variable. However, this does not solve the problem because $_SERVER['QUERY_STRING'] will still be: ?category=apples&color=red&pageno=3 even if ($_GET[pageno] == 4) now. Instead, I fixed it using substr(). While, admittedly is not the best solution, it will work for now. Here is my code: $qString = $_SERVER['QUERY_STRING']; $newqString = substr($qString, 0, strrpos($qString, '=') +1); echo "<dd class=\"next\"><a href=\"cc-nse-search.php"; print ($qString ? '?' . $newqString . "$next" : "?pageno=$next"); echo "\"> </a></dd>"; This code will remove anything past the last '=' sign and will replace it with the new number. This currently works because pageno is always the last variable in the URL, however, its probably not a permanent solution. If someone comes up with a better idea, can you post please? Thanks again guys, Steven Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880532 Share on other sites More sharing options...
ignace Posted July 22, 2009 Share Posted July 22, 2009 If someone comes up with a better idea, can you post please? function createQueryString($array = array(), $kvSep = '=', $varSep = '&') { $get = array_merge($_GET, $array); $getVars = array(); foreach ($get as $key => $value) { if (is_string($key)) { $getVars[] = implode($kvSep, array($key, $value)); } } return implode($varSep, $getVars); } <a href="page.php?<?php print createQueryString(); ?>"> <?php $_GET['pageno']++; ?> <a href="page.php?<?php print createQueryString(); ?>"> <a href="page.php?<?php print createQueryString(array('pageno' => 5)); ?>"> Outputs: <a href="page.php?category=apples&color=red&pageno=3"> <a href="page.php?category=apples&color=red&pageno=4"> <a href="page.php?category=apples&color=red&pageno=5"> Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880631 Share on other sites More sharing options...
bruce080 Posted July 22, 2009 Author Share Posted July 22, 2009 Wow. I like that a lot. Thanks Ignace. Quote Link to comment https://forums.phpfreaks.com/topic/166980-solved-repost-_get-variables/#findComment-880642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.