Page 1 of 1

Multiple $_GET parameters

Posted: Mon Aug 25, 2008 1:28 pm
by giles
Hi all,

I'm working on a development where I need to present the user with the option to change a number of forms before committing. Spaced out for reading, the passed url looks a little like this :

/index.php?
action=xyz&job_id=20&print=1&
action=xyz&job_id=25&print=1&
action=xyz&job_id=26&print=1&
action=xyz&job_id=27&print=1&
action=xyz&job_id=39&print=1

I know that $_GET and $_POST are forms of arrays. I’ve tried looking at them with the likes of print_r($_GET[’job_id’]), with little success.

So my basic question is : how do I handle multiple get or post parameters. I’d appreciate your comments

thank you
giles

Re: Multiple $_GET parameters

Posted: Mon Aug 25, 2008 1:38 pm
by soulcrazy
First:

Code: Select all

 
echo print_r($_GET);  // don't specify the key if you want to display all pairs in the array
 

Second, there are many approaches you can take. I like to:

Code: Select all

 
$getArray = explode('&', $_SERVER['QUERY_STRING']);
 
print_r($getArray) would look like:

$getArray(
[0] => 'action=xyz',
[1] => 'job_id=20',
[2] => 'print=1',
[3] => ''
);

You could the use explode again within each:

Code: Select all

$action = explode('=', $getArray[0]);
Although, the result is much the same as print_r($_GET);

Re: Multiple $_GET parameters

Posted: Mon Aug 25, 2008 1:44 pm
by Ziq
Replace this
giles wrote: /index.php?
action=xyz&job_id=20&print=1&
action=xyz&job_id=25&print=1&
action=xyz&job_id=26&print=1&
action=xyz&job_id=27&print=1&
action=xyz&job_id=39&print=1
on

Code: Select all

 
/index.php?
action[]=xyz&job_id[]=20&print[]=1&
action[]=xyz&job_id[]=25&print[]=1&
action[]=xyz&job_id[]=26&print[]=1&
action[]=xyz&job_id[]=27&print[]=1&
action[]=xyz&job_id[]=39&print[]=1
 
For example: (index.php)

Code: Select all

 
print_r($_GET);
 

Re: Multiple $_GET parameters

Posted: Mon Aug 25, 2008 1:52 pm
by pickle
You need to re-examine your approach. Why not something like:

index.php?xyz=1&print=1&job_id=20,25,26,27,39

Then use explode() to get all the job ids.

Re: Multiple $_GET parameters

Posted: Mon Aug 25, 2008 2:53 pm
by RobertGonzalez
Are you talking multiple GET variables with the same name or just more than one querystring param?

Re: Multiple $_GET parameters

Posted: Tue Aug 26, 2008 12:47 am
by giles
Thank you all for your comments

I can see that I might need to think on this a little. Here’s what I’m trying to do in a little more detail. I’m developing an online label application. I have a visitor making, recalling, and editing labels. The number of labels is totally flexible .... the serial number of each being cached in an array. just before printing, the array reads out the labels into a page where the visitor can select the number of each to print.

$action is the receiving script argument, xyz being the relevant case argument, so these need to be the same (I understand that this is also where I get into the problem of “over writing” values), job_id is the serial number of each record, print is the number of each label to print.

I can see that I need to get to something like......

index.php?action=xyz&job_id=20,25,26,27&print=1,1,2,1

but I’m not sure how to get there ... any thoughts?

Re: Multiple $_GET parameters

Posted: Tue Aug 26, 2008 1:25 am
by RobertGonzalez
What is building that query string?