Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need Help: Multiple URL Parameter

Community Beginner ,
Jan 09, 2011 Jan 09, 2011

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

TOPICS
Server side applications
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 09, 2011 Jan 09, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 09, 2011 Jan 09, 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 "&"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 09, 2011 Jan 09, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 09, 2011 Jan 09, 2011

Querystrings include lists of parameters separated by the ampersand. There is no concept of 'OR', nor is one required. It's up to your script to process the values in any way that's appropriate. If you are using these values in a SQL query, then your query would include OR logic. Or, if you want the possibility of processing as OR or as AND, then you can include an additional querysting parameter to store this logical value. Make sense?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 10, 2011 Jan 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 10, 2011 Jan 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!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 10, 2011 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 10, 2011 Jan 10, 2011
LATEST

Well I guess php does not handle this the same as other scripting languages I've used:

Go to

http://www.php.net/manual/en/function.parse-str.php

and read about how to handle duplicate field names.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 10, 2011 Jan 10, 2011

I think you are missing a step between the URL parameters and the SQL query. You have to interpret the input (URL parameters) and create the appropriate query, where you can use "OR".

Barry

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines