Jump to content


Photo

Adding vars to URL


  • Please log in to reply
5 replies to this topic

#1 mausie

mausie
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 25 September 2006 - 10:50 AM

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=1
But... 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

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 September 2006 - 10:55 AM

Take a look at $_SERVER['QUERY_STRING'].

#3 mausie

mausie
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 25 September 2006 - 12:08 PM

Ok that works but I can't get it into my link :/

I do print $bla
It 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=1

I 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=Results

it automaticly removes print

And explorer shows: http://HOST/file:/C:...uments/SQL_PHP/

??? I don't get that. I'm forcing it to use a string as link and it somehow removes parts automaticly.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 September 2006 - 01:35 PM

Could you post the code you are using here

Prehaps you want to do something like this for the Print link:
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>';


#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 25 September 2006 - 01:55 PM

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:
<?php
function 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("&amp;", $newVars);
}

echo "<a href=\"myfile.php?" . strip_query('print') . "&amp;print=1\">Print</a>\n";
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#6 mausie

mausie
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 26 September 2006 - 09:49 AM

Thanks wildteen88.
That works! But still I don't get why it removes lines from my string I made myself. Oh well :P
Anyway all thanks for helping me :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users