Jump to content

Adding vars to URL


mausie

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
Link to comment
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.
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.