Jump to content

Archived

This topic is now archived and is closed to further replies.

mausie

Adding vars to URL

Recommended Posts

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

Share this post


Link to post
Share on other sites
Take a look at $_SERVER['QUERY_STRING'].

Share this post


Link to post
Share on other sites
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:/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.

Share this post


Link to post
Share on other sites
Could you post the code you are using here

Prehaps 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]

Share this post


Link to post
Share on other sites
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]
<?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";
?>
[/code]

hope this helps

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.