URL query

Asked By Randy Inaneway
03-Nov-09 01:06 PM
Earn up to 0 extra points for answering this tough question.

I think I was able to query 2 values from 1 field but I can't remember how.

Example: field contains values 1, 2 , 3 for different records. I want to return 1 & 2 somthing like this:

pagename.asp?SWITCH=1

pagename.asp?SWITCH=2

that works fine but I want to return 1 AND 2

 

pagename.asp?SWITCH=1&2 does not work. It seems I did somthing like SWITCH=[1][2] or something similar some time ago and it worked but I just can't recall.

Is this possible or am I dreaming?

Thank you very much

 

 

 

 

 

 

  re

Web Star replied to Randy Inaneway
03-Nov-09 11:00 PM

in URL passing querystring '&' use for seprate two different variables in url so u don't use 1&2

so u can wnat to get two value passing in query string then try this way

pagename.asp?SWITCH=1,2

and then u will split on comma(,) and get 1 and 2

or u can use this

 pass two value then use two different variable as follows

pagename.asp?SWITCH=1&SWITCH2=2

  Couple of ways.

[)ia6l0 iii replied to Randy Inaneway
04-Nov-09 12:31 AM

You would use the same variable name with your multi-values and create the url. However, a note of caution that there is a length limit to the querystring. Instead you would ideally use other ways of communicating between two asp web pages.

And also note that the Ampersand ("&") is used to separates parameters and not to concatenate them.

You can also give the values as comma separated and then use the indices to retrieve each one of them. But again, this is not adviced as it involved code change in the dependant file once the query string changes in your calling code.

If the param in the Querystring is called "myParam" and has the value "a, b, c"; to retrieve all of them you would write,
Response.Write Request.QueryString("myParam")
And to retrieve each one of them you would do ,
Response.Write Request.QueryString("myParam")(1) ' would give a
Response.Write Request.QueryString("myParam")(2) ' would give b
Response.Write Request.QueryString("myParam")(3)
' would give c

also not that in ASP, you could give the same name to the request querystring variables and still retrieve values.
Like the following example.
http://localhost/webfolder/page1.asp?param1=a&param1=b&param1=c

Response.Write Request.QueryString("param1")(1) ' would give a
Response.Write Request.QueryString("param1")(2)' would give b
Response.Write Request.QueryString("param1")(3)' would give c

  asp

Jack jack replied to Randy Inaneway
09-Nov-09 02:09 AM

http://localhost/Website/page1.asp?n=1&n=2&n=3

for i=1 to Request.QueryString("n").Count
  Response.Write(Request.QueryString("n")(i) & "<br />")
next

It Will GIve
1
2
3

Create New Account