...

View Full Version : Is it possible to set a variable by clicking on a link?



Grant Palin
11-26-2003, 07:05 PM
I've got a PHP page with a few links on it. The links would show pages with different (but similar) information; e.g. I would make a similar query to MySQL to fill each page.

Can you set a variable in PHP whenever you click on a text link? What I want to do is reload the same page whenever a text link is clicked, using the value or text of that link as an argument or parameter to show different content. Can it be done? I could just write a seperate page for each link, but that kind of defeats the purpose of dynamic page generation.

I'm doing this with PHP + MySQL

Nightfire
11-26-2003, 08:34 PM
Quickest way is to do it by getting the variable from the url...

<a href="samepage.php?variable=somevalue">link</a>

And then just get the value of the variable from the $_GET['variable'] :)

Grant Palin
11-27-2003, 08:28 PM
Thanks, that works. Is there any other way it could be done?

SDP2006
11-27-2003, 09:09 PM
Thats the only way I know of. Why would you want to do it any other way?

Grant Palin
11-27-2003, 09:36 PM
I didn't know _AT_ALL_ how it could be done. I just wanted to know if there were other ways of doing it, like without adding the variable to the URL or something.

Nightfire
11-27-2003, 09:59 PM
The only other way I can think of is by using forms and having the text links submit info from hidden form fields, but that'll just get messy and just create more problem that it's worth

Grant Palin
11-27-2003, 10:40 PM
I guess so...Oh well, it's working, and I'm happy. Thanks again!:thumbsup:

Funkel
11-28-2003, 12:00 AM
You could use a session?

Nightfire
11-28-2003, 12:31 AM
...how would you change the info in the session from a link? ;) Without mentioning the two ways I mentioned, variables in a url or a form

Funkel
11-28-2003, 02:05 AM
I think I have read it all wrong

I thought he was trying to hold variables from page to page without having them in the URL

:o

Grant Palin
11-28-2003, 02:16 AM
Originally posted by Funkel

I thought he was trying to hold variables from page to page without having them in the URL

:o

It would have been nice, but, you know, whatever works;).

I'll have to take their word for it that there's no other way, at least until I learn more PHP...I'm only just getting going.

Funkel
11-28-2003, 02:24 AM
sorry, I am here just confusing the situation :)

Grant Palin
11-28-2003, 05:53 PM
Originally posted by Funkel
sorry, I am here just confusing the situation :)

There's one in every crowd!;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum