Page 1 of 1
Using GET
Posted: Sun Sep 30, 2007 9:03 am
by enchance
How do you pass a variable using GET when a text link is pressed? The only difference is that it reloads the current page but this time with a new value for the variable so it would be like it passed the new value to itself. Like if it were a gallery, it would just refresh itself with a new picture depending on the text link pressed.
Pardon if my question isn't all clear, I'm kinda new to php and am still trying to learn the ropes.
Posted: Sun Sep 30, 2007 9:06 am
by feyd
foo.php?something=somevalue
Posted: Sun Sep 30, 2007 10:25 am
by enchance
Oh, so you attach it to "href" Why didn't I think of that? I kept thinking in terms of javascript.
Posted: Sun Sep 30, 2007 10:29 am
by enchance
I was just thinking, if that sends it using GET, how do I do the same but this time using POST? Same scenario, all text links and no forms. This is just an afterthought.
Posted: Sun Sep 30, 2007 10:29 am
by superdezign
Right. GET and POST requests always look like"var1=value&var2=othervalue..." and the only difference is that GET requests are sent directly through the URL as a query string.
Posted: Sun Sep 30, 2007 11:46 am
by feyd
Links are unable to post.
Posted: Sun Sep 30, 2007 12:31 pm
by enchance
Oh, I see. Thanks, you've helped a lot!
Posted: Wed Oct 03, 2007 1:53 am
by enchance
I ran a small test but the image won't display. Check it out:
Code: Select all
<?php
if(isset($_GET['pic']))
{
$thispic = $_GET['pic'];
}
else
{
$thispic = 1;
}
$paths[1] = "orange.jpg";
$paths[2] = "green.jpg";
$paths[3] = "red.jpg";
?>
<img src="<?php $paths[thispic]?>" />
<a href="main.php?pic=1">Orange</a> <a href="main.php?pic=2">Green</a> <a href="main.php?pic=3">Red</a>
Did I miss anything?
Posted: Wed Oct 03, 2007 2:06 am
by mrkite
enchance wrote:
Did I miss anything?
an "echo" statement.
Posted: Wed Oct 03, 2007 2:11 am
by Hemlata
Posted: Wed Oct 03, 2007 3:28 am
by enchance
I get it now, thanks! Btw, that other link was also posted by me but I always post here first since I think this forum is much better.
Posted: Wed Oct 03, 2007 7:28 am
by enchance
It worked!