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
Multiple $_GET parameters
Moderator: General Moderators
Re: Multiple $_GET parameters
First:
Second, there are many approaches you can take. I like to:
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:
Although, the result is much the same as print_r($_GET);
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']);
$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]);Re: Multiple $_GET parameters
Replace this
For example: (index.php)
ongiles 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
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
Code: Select all
print_r($_GET);
Re: Multiple $_GET parameters
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.
index.php?xyz=1&print=1&job_id=20,25,26,27,39
Then use explode() to get all the job ids.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Multiple $_GET parameters
Are you talking multiple GET variables with the same name or just more than one querystring param?
Re: Multiple $_GET parameters
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?
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?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Multiple $_GET parameters
What is building that query string?