Page 1 of 1
Dynamically handling GET variables?
Posted: Sun Feb 17, 2008 11:24 am
by PhpDog
I am sending dynamically created GET variables to a php page.
Usually I use:
$offset = $_GET['offset'];
$mortgage = $_GET['mortgage'];
to use the incoming GET variables.
My dynamically created incoming GET variables take the form:
t1=2,t2=4,t3=1,t4=7 etc.
Is there a way I can dynamically grab these for something like:
$t1 = $_GET['t1'] etc?
Re: Dynamically handling GET variables?
Posted: Sun Feb 17, 2008 12:28 pm
by Christopher
It should be with ampersands for URL params:
mysite.com?t1=2&t2=4&t3=1&t4=7
Re: Dynamically handling GET variables?
Posted: Sun Feb 17, 2008 12:58 pm
by PhpDog
arborint wrote:It should be with ampersands for URL params:
mysite.com?t1=2&t2=4&t3=1&t4=7
Yes, I understand that. What I was fumbling to convey was that my variables follow a distinct sequence.
This is why I thought I may be able to 'automate' their capture.
Re: Dynamically handling GET variables?
Posted: Sun Feb 17, 2008 1:04 pm
by John Cartwright
PhpDog wrote:arborint wrote:It should be with ampersands for URL params:
mysite.com?t1=2&t2=4&t3=1&t4=7
Yes, I understand that. What I was fumbling to convey was that my variables follow a distinct sequence.
This is why I thought I may be able to 'automate' their capture.
In this case where the number of elements is unknown you might want to use an array to be able to easily loop over the variables.
mysite.com?t[]=2&t[]=4&t[]=1&t[]=7
Code: Select all
foreach ($_GET['t'] as $key => $foo) {
echo $key .':'. $foo .'<br />';
}
Re: Dynamically handling GET variables?
Posted: Sun Feb 17, 2008 1:53 pm
by PhpDog
Many thanks to everyone who answered.