Using GET

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Using GET

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

foo.php?something=somevalue
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Post by enchance »

Oh, so you attach it to "href" Why didn't I think of that? I kept thinking in terms of javascript.
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Links are unable to post.
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Post by enchance »

Oh, I see. Thanks, you've helped a lot!
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Post 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?
mrkite
Forum Contributor
Posts: 104
Joined: Tue Sep 11, 2007 4:19 am

Post by mrkite »

enchance wrote:
Did I miss anything?
an "echo" statement.
Hemlata
Forum Commoner
Posts: 35
Joined: Mon Sep 10, 2007 5:40 am
Location: India
Contact:

Post by Hemlata »

Hello,

Checkout response on http://forums.digitalpoint.com/showthread.php?t=496277

Regards,
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Post 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.
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Post by enchance »

It worked!
Post Reply