<%@ Language=VBScript %>
<% Option Explicit %>
<%
'Do we need to go somewhere else?
If Request("selSearchOpt") = "2" then
Response.Redirect "http://www.aspfaqs.com/ASPScripts/FAQSearch.asp?SearchText=" & Server.URLEncode(Request("SearchText"))
ElseIf Request("selSearchOpt") = "3" then
Response.Redirect "http://www.aspmessageboard.com/search/search.asp?SearchText=" & Server.URLEncode(Request("SearchText"))
End If
'OK, we need to get the search results from the database
Const RecsPerPage = 8
Dim iPageNo
iPageNo = Request.QueryString("Page")
if Not IsNumeric(iPageNo) or iPageNo = "" then iPageNo = 1
'Get the search terms... if we have no search terms, redirect the user to the
'starting search page.
Dim txtSearchTerms
txtSearchTerms = Replace(Request("SearchText"),"""","")
txtSearchTerms = Replace(txtSearchTerms,"'","''")
if txtSearchTerms = "" then Response.Redirect "/search/"
'Get rid of parenthesis in the search terms
txtSearchTerms = Replace(txtSearchTerms,"(","")
txtSearchTerms = Replace(txtSearchTerms,")","")
'Now, we've gotta split up the search terms on ORs and ANDs
Dim colTerms, orTerms
colTerms = split(txtSearchTerms," and ",-1,1)
Dim iUpperTerms, iLoop, iUpperOrTerms, iOrLoop
iUpperTerms = UBound(colTerms)
Dim strWhereClause
strWhereClause = ""
For iLoop = LBound(colTerms) to iUpperTerms
orTerms = split(colTerms(iLoop)," or ",-1,1)
iUpperOrTerms = UBound(orTerms)
strWhereClause = strWhereClause & "("
for iOrLoop = LBound(orTerms) to iUpperOrTerms
strWhereClause = strWhereClause & " Contents LIKE ""%" & Trim(orTerms(iOrLoop)) & "%"" "
if iOrLoop < iUpperOrTerms then strWhereClause = strWhereClause & " OR "
next
strWhereClause = strWhereClause & ")"
if iLoop < iUpperTerms then strWhereClause = strWhereClause & " AND "
Next
'Now, execute sp
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=4Guys"
Dim strSQL
strSQL = "sp_PagedResults " & iPageNo & "," & RecsPerPage & ",'" & strWhereClause & "'"
Dim objRS
Set objRS = objConn.Execute(strSQL)
Dim iMore
Dim strPageTitle
strPageTitle = "4GuysFromRolla.com - Search Results for " & txtSearchTerms
%>
*** THIS #include simply contains HTML formatting... feel free to remove it ***
<%
if objRS.EOF then Response.Redirect "/search/index.shtml?norecs=1"
iMore = CInt(objRS("MoreRecords"))
%>
4GuysFromRolla.com Search Results
Articles <%=FormatNumber((iPageNo-1)*RecsPerPage+1,0)%> - <%=FormatNumber(iPageNo*RecsPerPage,0)%>
of <%=FormatNumber(iPageNo*RecsPerPage+iMore,0)%>
<%
Dim strURL, strTitle, strDesc
%>
<%
'As long as we are not on page 1, we need to show the prev button
if iPageNo > 1 then %>
<% end if %>
<%
'We need to show next/prev if applicable
if iMore > 0 then
'we have more records %>
<% end if %>
Return to Search Page
<%
Do While Not objRS.EoF
'Build the URL to the forum
strURL = objRS("URL")
strTitle = objRS("Title")
strDesc = objRS("Description")
%>
<%=strTitle%>
<%=strDesc%><% objRS.MoveNExt Loop %>
| <% 'As long as we are not on page 1, we need to show the prev button if iPageNo > 1 then %> <% end if %> | <% 'We need to show next/prev if applicable if iMore > 0 then 'we have more records %> <% end if %> | Return to Search Page |
*** THIS #include simply contains HTML formatting... feel free to remove it *** <% objRS.Close Set objRS = Nothing objConn.Close set objConn = Nothing %>