mausie Posted September 25, 2006 Share Posted September 25, 2006 Hi,I'm working on a page that reads data of people from an database.I got a form working on GET method so all vars will be nicely in the address bar when submit.I want to add a print function. So when the page loads it will check if "Print version" (print == 1) has been clicked and it will show that content instead of the color content.The link contains PHP_SELF with ?print=1But... all other vars that were in the address bar are gone when clicked. So the new form get's all kinds of SQL errors.How could I fix this? Putting all GETS in a $var first. Or will it delete those contents too when PHP_SELF is called. Or Are there other techniques?Maurice Quote Link to comment https://forums.phpfreaks.com/topic/21957-adding-vars-to-url/ Share on other sites More sharing options...
trq Posted September 25, 2006 Share Posted September 25, 2006 Take a look at $_SERVER['QUERY_STRING']. Quote Link to comment https://forums.phpfreaks.com/topic/21957-adding-vars-to-url/#findComment-98054 Share on other sites More sharing options...
mausie Posted September 25, 2006 Author Share Posted September 25, 2006 Ok that works but I can't get it into my link :/I do print $blaIt shows: /file:/C:/Documents and Settings/mvdstar/My Documents/SQL_PHP/Index2.php?nameinput=&names=Star%2C+Maurice+van+der&year=2006&Results=Results&print=1I got $bla in <a href.The link (Firefox) shows:/file:/C:/Documents and Settings/mvdstar/My Documents/SQL_PHP/Index2.php?nameinput=&names=Star%2C+Maurice+van+der&year=2006&Results=Resultsit automaticly removes printAnd explorer shows: http://HOST/file:/C:/Documents%20and%20Settings/mvdstar/My%20Documents/SQL_PHP/ ??? I don't get that. I'm forcing it to use a string as link and it somehow removes parts automaticly. Quote Link to comment https://forums.phpfreaks.com/topic/21957-adding-vars-to-url/#findComment-98097 Share on other sites More sharing options...
wildteen88 Posted September 25, 2006 Share Posted September 25, 2006 Could you post the code you are using herePrehaps you want to do something like this for the Print link:[code=php:0]if(empty($_SERVER['QUERY_STRING'])){ $url = "?print=1";}elseif(!eregi("print=1", $_SERVER['QUERY_STRING'])){ $url = '?' . $_SERVER['QUERY_STRING'] . '&print=1';}else{ $url = '?' . $_SERVER['QUERY_STRING'];}// echo print link:echo '<a href="' . $url . '">Print</a>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21957-adding-vars-to-url/#findComment-98139 Share on other sites More sharing options...
obsidian Posted September 25, 2006 Share Posted September 25, 2006 here's a function i like to use when i'm doing pagination or other things where i need to retain all query items besides particular ones within a URL:[code]<?phpfunction strip_query($vars) { $var = !is_array($vars) ? array($vars) : $vars; $newVars = array(); foreach ($_GET as $key => $val) { if (!in_array($key, $vars) && !empty($val)) { $newVars[] = "{$key}={$val}"; } } return implode("&", $newVars);}echo "<a href=\"myfile.php?" . strip_query('print') . "&print=1\">Print</a>\n";?>[/code]hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/21957-adding-vars-to-url/#findComment-98156 Share on other sites More sharing options...
mausie Posted September 26, 2006 Author Share Posted September 26, 2006 Thanks wildteen88.That works! But still I don't get why it removes lines from my string I made myself. Oh well :PAnyway all thanks for helping me :) Quote Link to comment https://forums.phpfreaks.com/topic/21957-adding-vars-to-url/#findComment-98799 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.