How to obtain several variables from a URL?

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
db579
Forum Commoner
Posts: 37
Joined: Sun Jul 18, 2010 6:23 pm

How to obtain several variables from a URL?

Post by db579 »

I'm using links like

Code: Select all

 href=?example=$example 
and the using GET to to obtain whether or not $example has been set by clicking the link and what it has been set as.

An example is:

Code: Select all

$album = (isset($_GET['album']) ? $_GET['album']:'');
	$Array = scandir("gallery");
					foreach($Array as $directory){
							echo "<a href='?album=$directory'>$directory</a>";					
					}
					?> 
How I do this for several variables in one link? Have tried googling but can't seem to find the right syntax anywhere. Thanks very much
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: How to obtain several variables from a URL?

Post by Weirdan »

Code: Select all

<a href="?var1=something&var2=somethingElse">click</a>

Code: Select all

<a href="?<?php echo http_build_query(array('var1' => 'something', 
                                            'var2' => 'somethingElse'), 
                                            '', '&')?>">click</a>
db579
Forum Commoner
Posts: 37
Joined: Sun Jul 18, 2010 6:23 pm

Re: How to obtain several variables from a URL?

Post by db579 »

Thank you very much! Was literally tearing my brains out over this but that works perfectly!
Post Reply