Skip to main content
Known Participant
January 9, 2011
Question

Need Help: Multiple URL Parameter

  • January 9, 2011
  • 2 replies
  • 1521 views

Hello,


I want to add multiple URL parameters to link.


what i have now is this:
../results.php?type=1&type=2

but the parameter should pass this:
type=1 OR type=2

Thanks

This topic has been closed for replies.

2 replies

IFemanAuthor
Known Participant
January 10, 2011

Hi,

Explaining my question, let's say I have  link called "Books",  it should take you

to "result page" and shows all results:

where type="children_books" and type="Sci_Fi_books" and "novels"

When I add this URL Parameter for the link:
../results.php?type=1&type=2&type=3  (3 is "novels")
the result page shows only "novels" results, so I thought  there is maybe a way to write "or" instead of "&" !

If I can't do this with URL parameters, how can I?

Thanks
BenPleysier
Community Expert
Community Expert
January 10, 2011
../results.php?type=1&type=2&type=3  (3 is "novels")

That is because you have given 3 different values for the 'type' variable. Naturally it will assume the last value.

In your case you should either pass just one variable or two or three variables with different names.

In case of the first option you can have type=1 for children, type=2 for Sci_Fi or type=3 for novels as follows

../results.php?type=2 /*Sci_Fi

In case of the latter you can sort it out by using decision making statements like you will have somthing like

../results.php?chilren=1&Sci_Fi=0&novel=0 /*for children

Gramps

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Participating Frequently
January 10, 2011

>> ../results.php?type=1&type=2&type=3

Gramps, assigning more than one value to a field in a querystring is perfectly valid. However, I know nothing about PHP so I'm not sure what the method would be to extract all of them. I imagine there's a way to iterate through the field list and extract the values.

Participating Frequently
January 9, 2011

It's not clear to me what your problem is. A field in a querystring can be associated with more than one value, as you are doing in your first example.  It's up to your script to then parse it and determine what to do with it. Can you explain in a little more detail what you are trying to do?

IFemanAuthor
Known Participant
January 9, 2011

Hi, thanks for responding.
What i want the parameter to pass is EITHER [ type=1 OR type=2 ] but as in my first  example i only know how to add a parameter that passes both types with "&"

January 10, 2011

Although URL parameter passing looks positional, php actually parses the string that is passed so that

page2.php?Type1="foo"

and

page2.php?Type2="bar"

both work provided you parse the string as $_GET['Type1']." and ".$_GET['Type2']

If you don't know what type the strings are when you create the URL string so that you can not label them correctly, then your only recourse would be to parse the string to decide what it contains.

Can you give a more concrete example of what you are trying to accomplish?