PDA

View Full Version : Passing a variable in a link


Robin_W
06-06-2001, 09:52 PM
I'm a near-total newbie at PHP4 (can do include files and email forms, that's about it), and have a slightly convoluted problem here. How do you pass a variable via a link in PHP4?

I have a columnist on my Website and I want to have an archive of his old columns for visitors.

The archived columns are actually plaintext files. I have an index page listing the columns as a series of links. There's another page which is meant to load the column requested as a server-side include.

What I want to have happen is this: Each link includes a variable that it passes to that second page, which tells it which text file to use for the include. Am I making sense so far?

Here's the code I *tried* to use on the links page, which you can see at http://www.liberalmafia.org/agitprop/racano/archives/:


<? echo &quot;<a href=&quot;\column.php4?$the_url=5.18.2001.txt'>May 18, 2001</a>
&quot;; ?>


And this is the code I've got on the column page:


<? include &quot;$the_url&quot; ?>


Obviously, something here is wrong. Any advice would be appreciated.

Eventually, no doubt, I'll figure out how to write code that automaticallyly archives the columns and generates the links page, but that's far in the future while I refresh my C++ and learn how to use MS-DOS....[nbsp]

dank
06-06-2001, 11:36 PM
That example should be:

<? echo &quot;<a href=&quot;\column.php4?the_url=5.18.2001.txt'>May 18, 2001</a>
&quot;; ?>

You don't want a dollar sign in front of &quot;the_url&quot;.[nbsp][nbsp]When a PHP page receives a query string (stuff after the question mark) in the form of variable=value, then &quot;variable&quot; becomes an actual variable.[nbsp][nbsp]What you were trying to do by placing the $ in front of the variable name at the sending end of things was actually trying to substitute $the_url's value into the link.[nbsp][nbsp]If $the_url did not have a value assigned within the page, then you were really sending a URL of the form:

column.php4?=5.18.2001.txt

which should be confirmable by looking at the URL in the address bar after clicking on the link.

Dan

Robin_W
06-07-2001, 12:03 PM
My most grateful thanks to you, Dank! The beast works now. I am in your debt. :-)

PS: There's a double quote there that should be a single. Not to be a jerk, just to reassure you that it didn't throw me.

dank
06-07-2001, 12:36 PM
You're welcome.[nbsp][nbsp]Consider your debt repaid if you help the world, or at least Aota's corner of the world, remember not to capitalize the &quot;d&quot; in dank...

I didn't even notice the double quote in the code snippet.[nbsp][nbsp]:)[nbsp][nbsp]Since you have it escaped, it probably would still work, though.[nbsp][nbsp]Even Netscape is often able to figure out quote (single and/or double) discrepancies in URLs and image tags.

Dan

Robin_W
06-07-2001, 05:01 PM
Oops! Sorry about that.