Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post

    Is it possible to set a variable by clicking on a link?

    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

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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']

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks, that works. Is there any other way it could be done?

  • #4
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats the only way I know of. Why would you want to do it any other way?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    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

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    I guess so...Oh well, it's working, and I'm happy. Thanks again!

  • #8
    New Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could use a session?

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    ...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

  • #10
    New Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    Originally posted by Funkel

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

    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.

  • #12
    New Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, I am here just confusing the situation

  • #13
    Regular Coder
    Join Date
    Jun 2002
    Location
    Victoria, BC, Canada
    Posts
    962
    Thanks
    0
    Thanked 1 Time in 1 Post
    Originally posted by Funkel
    sorry, I am here just confusing the situation
    There's one in every crowd!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •