Welcome to WebmasterWorld Guest from 18.232.124.77

Forum Moderators: ocean10000

Message Too Old, No Replies

classic asp: need url to have multiple conditions

classic asp: need url to have multiple conditions

     
2:15 pm on Sep 24, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0



Hi there,
I hope this can help some other people also.

I need a link to have 2 search criteria/ conditions. For instance, page.asp?UserSkills=Webdeveloper&AccountType=Seller

which I have coded as:
<a href='search.asp?UserSkills=" & Trim(Request("UserSkills")) &"&AccountType=" & Trim(Request("AccountType")) &"'>

the problem I'm having is that when the AccountType is 'Buyer' I need the URL to search for 'Seller' and when the AccountType is 'Leasing' I need the URL to search for 'Renting'

I have created a number of variables to use
<% Dim varSeller, varBuyer, varLease, varRent
varSeller = "Seller"
varBuyer = "varBuyer"
varLease = "varLease"
varRent = "varRent"
%>

now I need some sort of an 'if' statement to make it work.

So if the current account type on this page is 'Seller' search for 'buyer' in the search.asp page and vice versa then I have to cram it into the URL.

I wonder can anyone help me here? I hope I explained this properly.

2:34 pm on Sept 24, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


I'm not sure if I understand, do you mean something like this?

<%
Select Case LCase(Request.QueryString("AccountType"))
Case "buyer"
' Search for Sellers
Case "leasing"
' Search for renters
Case Else
' Do something else
End Select
%>
2:44 pm on Sept 24, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0


If the AccountType of the current user (so we are on user.asp?userID=34) is a buyer, I need to search for a seller. If the AccountType is a seller I need to search for a buyer. So I'm trying to put buyers and sellers together and other account types together if you know what I mean.
2:54 pm on Sept 24, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


I think I understand now, would something like this work?

<%
Dim myQueryAccountType

Select Case Trim(LCase(Request("AccountType")))
Case "buyer"
myQueryAccountType = "seller"

Case "seller"
myQueryAccountType = "buyer"

Case "leasing"
myQueryAccountType = "renting"

Case "renting"
myQueryAccountType = "leasing"

End Select

Response.Write "<a href='search.asp?UserSkills=" & Trim(Request("UserSkills")) &"&AccountType=" & myQueryAccountType &"'>"

%>

2:58 pm on Sept 24, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0


Oh that looks like what I'm looking for. I'll give that a go. Thanks a lot Marcel. That's great...

...just have to get it to work now :)

7:40 pm on Sept 24, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0


Hi again guys.

I need to merge both of these pieces of code into one...

<%
Dim myQueryAccountType

Select Case Trim(LCase(Request("AccountType")))
Case "buyer"
myQueryAccountType = "seller"

Case "seller"
myQueryAccountType = "buyer"

Case "leasing"
myQueryAccountType = "renting"

Case "renting"
myQueryAccountType = "leasing"

End Select

Response.Write "<a href='search.asp?UserSkills=" & Trim(Request("UserSkills")) &"&AccountType=" & myQueryAccountType &"'>"

%>

<%

Dim myKeywords
myKeywords = "music, dance, chat, property"

Dim myKeywordArray
myKeywordArray = Split(myKeywords, ",")

For i = 0 to UBound(myKeywordArray)
response.write "<a href='/Search.asp?query=" & Trim(myKeywordArray(i)) & "'>" & Trim(myKeywordArray(i)) & "</a>, "
Next

%>

I had a go at doing it like this but I'm a bit of a novice at arrays. I suppose if these codes were chemicals I would have blown myself up eh? I wonder could anyone help me solve my conundrum?

<%

Dim myKeywords
myKeywords = Rsusers("UserSkills")
Dim myKeywordArray
myKeywordArray = Split(Rsusers("UserSkills"), ",")

Dim myQueryAccountType

Select Case Trim(LCase(Request("AccountType")))
Case "buyer"
myQueryAccountType = "seller"
Case "seller"
myQueryAccountType = "buyer"
Case "leasing"
myQueryAccountType = "renting"
Case "renting"
myQueryAccountType = "leasing"

End Select

For i = 0 to UBound(myKeywordArray)

response.write "<a href='search.asp?UserSkills=" & Trim(myKeywordArray(i)) &"&AccountType=" & myQueryAccountType &"'>" & Trim(myKeywordArray(i)) & "</a>, "

%>

Thanks for any help offered.
Kev.

7:43 pm on Sept 24, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0


Also, one more thing. Is there a way of checking if the UserSkills field is empty first and creating some sort of 'else' statement? I tried an <% if isarray(myKeywords) then %>statement but it didn't work too well. :(
5:06 am on Sept 25, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


the only thing you seem to be missing in your code is the next in your for-next loop;
...
For i = 0 to UBound(myKeywordArray)

response.write "<a href='search.asp?UserSkills=" & Trim(myKeywordArray(i)) &"&AccountType=" & myQueryAccountType &"'>" & Trim(myKeywordArray(i)) & "</a>, "
Next
%>

Also, you can scrap the first two lines as they are unnecessary, because you are splitting the recordset directly

Dim myKeywords
myKeywords = Rsusers("UserSkills")
5:10 am on Sept 25, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


to check to see if the UserSkills field is Nothing or an Empty String you can do the following
If Rsusers("UserSkills") & "" = "" then

Or you can check the UBound value of the Array to see if it is zero.

9:11 am on Sept 25, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0


Yeah, I'm getting a 'type mismatch' in the UBound.
9:39 am on Sept 25, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


Sorry, I'm not that great at classic ASP, I think this will work:

if isEmpty(myKeywordArray(0)) then ...

1:14 pm on Sept 25, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0


It almost works now :) the only problem I have is that the 'AccountType' isn't showing in the URL. So you'll have:

search.asp?UserSkills=drums&AccountType=
instead of:
search.asp?UserSkills=drums&AccountType=seller

I have the script written exactly as it is in the above message:
...
For i = 0 to UBound(myKeywordArray)
response.write "<a href='search.asp?UserSkills=" & Trim(myKeywordArray(i)) &"&AccountType=" & myQueryAccountType &"'>" & Trim(myKeywordArray(i)) & "</a>, "
Next
%>

I wonder could anyone help me? If I get this sorted out I have 4 more pages that I can fix up in 10 mins as they all have the same problem :(

Thanks for any help offered.
Kevin

1:18 pm on Sept 25, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


try adding the bolded code to your select Case Statement:

Case "renting"
myQueryAccountType = "leasing"
Case Else
myQueryAccountType = "UnexpectedAccountType"

End Select

If you get &AccountType=UnexpectedAccountType in your query string then try outputting the given value with Response.Write(Request("AccountType")) to see what value it contains
1:45 pm on Sept 25, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0


Yeah that happened. It came up with UnexpectedAccountType. I put a Response.Write(Request("AccountType")) piece into the page and it is taking the AccountType from the URI which is the way it is supposed to be I gather?

What do you mean by 'try outputting the given value with Response.Write(Request("AccountType")) to see what it contains' do you mean put Response.Write(Request("UnexpectedAccountType")) into the page to see what it shows?

3:00 pm on Sept 25, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


What do you mean by 'try outputting the given value with Response.Write(Request("AccountType")) to see what it contains' do you mean put Response.Write(Request("UnexpectedAccountType")) into the page to see what it shows?

I meant what you did yourself: 'I put a Response.Write(Request("AccountType")) piece into the page'

I think we have our wires crossed somehow, I assumed that you were querying the value of AccountType to generate a new URL?

3:29 pm on Sept 25, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0



Sorry, yes. If the page I am on = "seller" which means the account type coming out of the database is also "seller" and "seller" is also in the URL because I am using the same page for multiple pages so I have four pages:
<a href="page.asp?AccountType=Buyer">Buyers</a>
<a href="page.asp?AccountType=Seller">Sellers</a>
etcetera if you know what I mean.

So if the URL or AccountType the database (aren't they both the same?) is Seller the AccountType = Buyer

I hope I'm not confusing you.

9:35 am on Sept 28, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


I think I would actually do what I proposed in my first post. ie. don't change the Accounttype in the URL (so it always remains constant), but find the accountType on the search page and define your search based on the current account type.

So, on the search page itself, have something like the following:

<%
Select Case LCase(Request.QueryString("AccountType"))
Case "buyer"
' Search for Sellers
Case "leasing"
' Search for renters
Case Else
' Do something else
End Select
%>

(I would also consider storing the AccountType in a session variable instead of constantly passing it from page to page)

9:11 am on Sept 29, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 11, 2009
posts:108
votes: 0


Ok, thanks, I will try this.

THanks again.