View Full Version : Extracting from URL depending upon the query used
AdamC
06-15-2005, 11:34 AM
I am editing a site that has a search funtionality that searches an inventory by county and town.
Each town is associated with a county (located in).
The search url is either:
search.asp?var=x&County=example
or
search.asp?var=x&Town=example
I want to be able to extract the the County or the Town for use on the page dependant on which query is used. At the moment it is extracting the just town regardless.
Have I described the problem well enough?
NancyJ
06-15-2005, 12:22 PM
if request.querystring("Town") then
'do town query
else
if request.querystring("County") then
'do county query
else
'error
end if
end if
Morgoth
06-15-2005, 08:59 PM
NancyJ, you should use indenting, and I got really confused when reading that. I beleive you do not need to embed the two if statements.
AdamC, I beleive this is all you really need. NancyJ's code would work just as well as mine, but embeding If statements lead to problems.
This would work just as well.
If Request.QueryString("Town") Then
'do town query
ElseIf Request.QueryString("County") Then
'do county query
Else
'error or neither
End If
AdamC
06-20-2005, 05:31 PM
Just tried your code as follows:
If Request.QueryString("Town") Then
'do town query
RESPONSE.WRITE "<h1>" & objRS("Town") & "</h1>"
ElseIf Request.QueryString("County") Then
'do county query
RESPONSE.WRITE "<h1>" & objRS("County") & "</h1>"
Else
'error or neither
RESPONSE.WRITE "<h1>error</h1>"
End If
but its not having it. Any ideas?
Freon22
06-20-2005, 07:09 PM
So is it printing out the Else part. Response.Write("<h1>error</h1>")
When I first seen your thread and seen the rely, I wasn't sure it was going to work. So I waited to see!
I always throught that an If statement was a conditional statements. So when you say
If Request.QueryString("Town") Then
It doesn't mean anything. Unless there is a default condition in the If statement that I don't know about. If not then You have to say somethine like.
If Request.QueryString("Town") = something Then
So I thought that this code should have been writen like this.
If Not Request.QueryString("Town") = "" Then
'do town query
RESPONSE.WRITE "<h1>" & objRS("Town") & "</h1>"
ElseIf Not Request.QueryString("County") = "" Then
'do county query
RESPONSE.WRITE "<h1>" & objRS("County") & "</h1>"
Else
'error or neither
RESPONSE.WRITE "<h1>error</h1>"
End If
Or you could write this like
If Request.QueryString("Town") <> "" Then
'do town query
RESPONSE.WRITE "<h1>" & objRS("Town") & "</h1>"
ElseIf Request.QueryString("County") <> "" Then
'do county query
RESPONSE.WRITE "<h1>" & objRS("County") & "</h1>"
Else
'error or neither
RESPONSE.WRITE "<h1>error</h1>"
End If
The only trouble with this way is if both "Town" and "County" has something in them then the code may not have a normal out come.
:)
I keep editing this post, but I have a question. If you Request a QueryString that doesn't exist, will you get a error?
Morgoth
06-20-2005, 09:02 PM
I always throught that an If statement was a conditional statements.
If the condition equals "True" then it will work the same as just having a variable equal "True" or positive or not equal "".
This works:
If True Then
Response.Write "This is true"
End If
Why not test other possibilities?
Freon22
06-20-2005, 09:08 PM
Thanks Morgoth,
I didn't know that, this is one of the reasons I like being on a board like this. You learn something new all the time.
AdamC
06-21-2005, 10:44 AM
If Not Request.QueryString("Town") = "" Then
'do town query
RESPONSE.WRITE "<h1>" & objRS("Town") & "</h1>"
ElseIf Not Request.QueryString("County") = "" Then
'do county query
RESPONSE.WRITE "<h1>" & objRS("County") & "</h1>"
Else
'error or neither
RESPONSE.WRITE "<h1>error</h1>"
End If
Thanks Freon22, that works a treat
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.