Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing an array via GET

Status
Not open for further replies.

returnButton

Programmer
Mar 31, 2009
7
GB
Hi.. I'm trying out a GET form for the 1st time, and I want to pass a load of fields as an array. This is for a filter, which will have things like "start from page", "display per page", "category type" etc etc.

I've named all the fields the same, ie

Code:
<input name="filter[]" value="start:1">
<input name="filter[]" value="perpage:10">

and when submitted I get

Code:
&filter[]=start:1&filter[]=perpage:10

Ideally I would like this passed as one variable, something like:

Code:
&filter[]=start:1,perpage:10

That way, I can just deal with one variable in my PHP. Plus, the URL is a lot shorter & neater.

Is this doable? Anyone done anything like this before? thanks : )
 
&filter[]=start:1&filter[]=perpage:10
This is right, you are not getting several variables but just 1 filter[]

Browsers will pass the variables like that, however PHP is smart and will automatically convert the list of same name variables into an array because they have [] at the end.

So you can access the variable as $_GET['filter'][0] for the fist one $_GET['filter'][1] for the second etc...

Yes the URL will look very ugly, but there is nothing you can do about it.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
You can also try using implode() to convert your array into a string in the sending page then explode() it back into an array in the receiving page.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top