You have to check for it, regardless. See if this works for you.

$url = $_SERVER['REQUEST_URI'] . '?' . ((isset($_SERVER['QUERY_STRING'])) ?
$_SERVER['QUERY_STRING'] . '&' : '' ) . 'newVar=1';

The middle part basically sees if the QUERY_STRING is empty. If it is, it
includes a question mark otherwise it includes an apersand. Actually, to be
fully compliant, replace the & with & in your URLs.

$url = $_SERVER['REQUEST_URI'] . '?' . ((isset($_SERVER['QUERY_STRING'])) ?
$_SERVER['QUERY_STRING'] . '&' : '' ) . 'newVar=1';

It'll work, trust me. :)

---John Holmes...

----- Original Message -----
From: "Matt Grimm" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 28, 2003 4:12 PM
Subject: [PHP] Appending to the REQUEST_URI


Let's say I have a table with links in the headers for sorting each column.
I want to carry the sort variable along in the $_GET array, and I need to be
able to pass other variables to this same page, also using the GET method.
My trouble is when I need to append a new variable to the REQUEST_URI -- I
need to detect whether a QUERY_STRING has already been passed, so I won't
use "?" when I need "&" in the URI.  Here's my clunky attempt:

<a href="<?php
echo $_SERVER['REQUEST_URI'];
if ($_SERVER['QUERY_STRING'] && !$_GET['newVar']) {
    echo "&newVar=1";
}
else if (!$_SERVER['QUERY_STRING']) {
    echo "?newVar=1";
}
?>
">link description text</a>

Please tell me there is some way to just append to the query string without
checking it first...

--
Matt Grimm
Web Developer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Parkway
Anchorage, AK 99508
907.770.6200 ext. 686
907.336.6205 (fax)
E-mail: [EMAIL PROTECTED]
Web: www.healthtvchannel.org


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to