Forum Moderators: open

Message Too Old, No Replies

classic asp: need url to have multiple conditions

classic asp: need url to have multiple conditions

         

KRMwebdesign

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

10+ Year Member




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.

marcel

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

WebmasterWorld Senior Member 10+ Year Member



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
%>

KRMwebdesign

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

10+ Year Member



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.

marcel

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

WebmasterWorld Senior Member 10+ Year Member



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 &"'>"

%>

KRMwebdesign

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

10+ Year Member



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 :)

KRMwebdesign

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

10+ Year Member



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.

KRMwebdesign

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

10+ Year Member



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. :(

marcel

5:06 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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")

marcel

5:10 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

KRMwebdesign

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

10+ Year Member



Yeah, I'm getting a 'type mismatch' in the UBound.

marcel

9:39 am on Sep 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

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

KRMwebdesign

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

10+ Year Member



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

marcel

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

WebmasterWorld Senior Member 10+ Year Member



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

KRMwebdesign

1:45 pm on Sep 25, 2009 (gmt 0)

10+ Year Member



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?

marcel

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

WebmasterWorld Senior Member 10+ Year Member



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?

KRMwebdesign

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

10+ Year Member




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.

marcel

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

WebmasterWorld Senior Member 10+ Year Member



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)

KRMwebdesign

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

10+ Year Member



Ok, thanks, I will try this.

THanks again.