Adv search string -
08-13-2004
, 01:15 AM
I currently have the following code creating a search string and it works
fine until you get to the lower portion if you enter a keyword(search1) it
works fine but if you select a year(years1) it does not return the correct
results and if you dont have a keyword and just want to search by year it
gives me an error because of the AND statement. If anyone can help im kinda
new at this it would be greatly appreciated.
<% Dim SearchString
' Looks for a Category or User
If Request.QueryString("CategoryID") <> "" THEN SearchString = SearchString
& " CategoryID = " & Request.QueryString("CategoryID") END IF
If Request.QueryString("UserID") <> "" THEN SearchString = SearchString & "
UserID = " & Request.QueryString("UserID") END IF
' Search by days
If Request.QueryString("Days") = "3" THEN SearchString = SearchString & "
AdDate >= Date() - 3" END IF
If Request.QueryString("Days") = "7" THEN SearchString = SearchString & "
AdDate >= Date() - 7" END IF
If Request.QueryString("Days") = "14" THEN SearchString = SearchString & "
AdDate >= Date() - 14" END IF
' Looks for search critera from search page
If Request.QueryString("Search1") <> "" THEN SearchString = SearchString & "
Description LIKE '%" & Request.QueryString("Search1") & "%' OR Detailinfo
LIKE '%" & Request.Form("Search1") & "%'" END IF
If Request.QueryString("Years1") <> "0" THEN SearchString = SearchString & "
AND YearID = " & Request.QueryString("Years1") END IF
If Request.QueryString("Brands1") <> "0" THEN SearchString = SearchString &
" AND BrandID = " & Request.QueryString("Brands1") END IF
If Request.QueryString("Scales1") <> "0" THEN SearchString = SearchString &
" AND ScaleID = " & Request.QueryString("Scales1") END IF
SearchString = SearchString
%>
<%
Dim rsResults
Dim rsResults_numRows
Set rsResults = Server.CreateObject("ADODB.Recordset")
rsResults.ActiveConnection = MM_DCT_STRING
rsResults.Source = "SELECT * FROM ResultsQuery WHERE " & SearchString & "
ORDER BY AdDate DESC"
rsResults.CursorType = 0
rsResults.CursorLocation = 2
rsResults.LockType = 1
rsResults.Open()
rsResults_numRows = 0
%>
Steve |