jaco Posted September 24, 2009 Share Posted September 24, 2009 Hello everyone, I am having a problem with a pagination script to be used to display table results. The script for the Next button reads like this: echo '<a href=http://www.lightmypump.com/pumpdatabase2/return-pump-pagination.php?s='. ($start + $display) . '&cp=' . ($current_page+1) . '&p_type=' . $searchpumptype .'><b><big>Next </big></b></a>>';</big></b></a>>'; this basically is a link to the same page with some variables sent to the server and recalled using: if (isset($_GET['p_type'])) $searchpumptype = $_GET['p_type']; else $searchpumptype = $_GET['searchpumptype']; the problem is some of these variables are 2 words separated by a blank space such as "centrifugal horiz." The var. that is returned by the server for p_type is "centrifugal" it omits the second word and this screws things up. I am now thinking of very complicated ways to eliminate the blank space and then add it back later. But maybe there is a simple solution? CHeers, Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted September 24, 2009 Share Posted September 24, 2009 you can replace spaces with underscores than when y ou get the var, replace underscores with spaces again echo '<a href=http://www.lightmypump.com/pumpdatabase2/return-pump-pagination.php?s='. ($start + $display) . '&cp=' . ($current_page+1) . '&p_type=' . str_replace(" ", "_", $searchpumptype) .'><b><big>Next </big></b></a>>';</big></b></a>>'; Quote Link to comment Share on other sites More sharing options...
jaco Posted September 24, 2009 Author Share Posted September 24, 2009 Yes, that's an option. Thank you. I suppose I could also use the explode function which gets rid of the blank and creates an array and then the implode function which reverses it. Why does the server not see the word_blank_word combination as a complete string? Cheers, Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted September 24, 2009 Share Posted September 24, 2009 I'm not entirely sure why its truncating your string. When i do the following code echo htmlentities("<a href=".$_GET['taco'].">taco</a>"); with the following value for $_GET['taco']; my name is mikey the output is <a href=my name is mikey>taco</a> Quote Link to comment Share on other sites More sharing options...
jaco Posted September 24, 2009 Author Share Posted September 24, 2009 Yes, I know it's a bit of a mistery. When I use GET within a form action I get all the blanks. It seems that when this is initiated from a link this does not occur. Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted September 24, 2009 Share Posted September 24, 2009 Mystery's are much easier to solve with all the info... i.e. post the whole script Quote Link to comment Share on other sites More sharing options...
jaco Posted September 25, 2009 Author Share Posted September 25, 2009 Right you are Matthew. Here is a shortened version of the code that shows the behavior. The dropdown has two selections: a single word and a two word string with a blank space. If you select the single word and press the Display button you get it back as is. If you press the Next link you also get the word back as is. If you select the double word and press Next you get back the first part of the word only. Code: <?php // standard html web header require 'header.html'; // html user data input form echo "<form action =". $_SERVER['PHP_SELF']." method = \"GET\">"; if (isset($_GET['p_type'])) $searchpumptype = $_GET['p_type']; else $searchpumptype = $_GET['searchpumptype']; echo "<br />"; echo "searchpumptype is: ".$searchpumptype; echo "<br />"; echo "<b>Pump type</a>: "; echo "<select name=\"searchpumptype\">"; if ($searchpumptype == "bellows") echo "<option SELECTED value=\"bellows\">bellows</option>"; else echo "<option value=\"bellows\">bellows</option>"; if ($searchpumptype == "centrifugal horiz") echo "<option SELECTED value=\"centrifugal horiz\">centrifugal horiz</option>"; else echo "<option value=\"centrifugal horiz\">centrifugal horiz</option>"; echo "<br />"; echo "<input type=\"submit\" value=\"Display\" title =\"Hit this button whenever you change any of the above\">"; echo "</form>"; echo '<a href=test.php?p_type=' . $searchpumptype .'><b><big>Next </big></b></a>>'; // standard html web page footer require 'footer.html'; ?> You can run the script on my web site here: http://www.lightmypump.com/pumpdatabase2/test.php Cheers, J Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 25, 2009 Share Posted September 25, 2009 There is no mistery here. I have not readall the code, but there are two things you need to do: 1. Enclose HTML tag parameters in quotes. Wrong: echo '<a href=' . $value . '>Link</a> If the $value has a space in it the result will be <a href=some value.htm>Link</a> Right: echo "<a href=\"{$value}\"'>Link</a> Also, for any vlaue being put into a URL string you should use urlencode to convert any problematic characters for URL parsing: $value = urlencode($value); echo "<a href=\"{$value}\"'>Link</a> Quote Link to comment Share on other sites More sharing options...
jaco Posted September 25, 2009 Author Share Posted September 25, 2009 Thank you very much, seems the problem was with the use of the singlw quote. The following mods. work: echo "<a href=\"test.php?p_type=$searchpumptype\">"."<b><big>Next </big></b></a>>"; this works: echo "<a href=\"test.php?p_type={$searchpumptype}\">"."<b><big>Next </big></b></a>>"; and this works: $value = urlencode($searchpumptype); echo "<a href=\"test.php?p_type={$value}\">"."<b><big>Next </big></b></a>>"; Quote Link to comment 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.