<%@ 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 *** <!--#include virtual="/top.shtml"--> <% if objRS.EOF then Response.Redirect "/search/index.shtml?norecs=1" iMore = CInt(objRS("MoreRecords")) %> <CENTER><FONT SIZE=+2><B> <A HREF="http://www.4guysfromrolla.com/">4GuysFromRolla.com</A> Search Results </B></FONT><BR><FONT SIZE=2> Articles <%=FormatNumber((iPageNo-1)*RecsPerPage+1,0)%> - <%=FormatNumber(iPageNo*RecsPerPage,0)%> of <%=FormatNumber(iPageNo*RecsPerPage+iMore,0)%> </FONT></CENTER><P><HR><P> <% Dim strURL, strTitle, strDesc %> <TABLE CELLPADDING=10 WIDTH=100% BORDER=0> <TR><TD><!--iMore=<%=iMore%>--> <% 'As long as we are not on page 1, we need to show the prev button if iPageNo > 1 then %> <FORM METHOD=POST ACTION="Search.asp?Page=<%=iPageNo-1%>" id=form1 name=form1> <INPUT TYPE=HIDDEN NAME=SearchText VALUE="<%=txtSearchTerms%>"> <INPUT TYPE=SUBMIT VALUE=" < Prev <%=RecsPerPage%> articles " TITLE="Click to see the next <%=RecsPerPage%> matches." id=SUBMIT1 name=SUBMIT1> </FORM> <% end if %> </TD><TD> <% 'We need to show next/prev if applicable if iMore > 0 then 'we have more records %> <FORM METHOD=POST ACTION="Search.asp?Page=<%=iPageNo+1%>" id=form1 name=form1> <INPUT TYPE=HIDDEN NAME=SearchText VALUE="<%=txtSearchTerms%>"> <INPUT TYPE=SUBMIT VALUE=" Next <%=RecsPerPage%> articles > " TITLE="Click to see the next <%=RecsPerPage%> matches." id=SUBMIT1 name=SUBMIT1> </FORM> <% end if %> </TD><TD ALIGN=RIGHT WIDTH=*><FONT SIZE=2><A HREF="/search/">Return to Search Page</A></FONT></TD></TR> </TABLE> <% Do While Not objRS.EoF 'Build the URL to the forum strURL = objRS("URL") strTitle = objRS("Title") strDesc = objRS("Description") %> <FONT SIZE=+1><A HREF="<%=strURL%>"><B><%=strTitle%></B></A></FONT><BR> <FONT SIZE=2> <%=strDesc%></a></code></b></i></FONT><BR> [<A HREF="<%=strURL%>">Read More</A>] <P> <% objRS.MoveNExt Loop %> <TABLE CELLPADDING=10 WIDTH=100% BORDER=0> <TR><TD> <% 'As long as we are not on page 1, we need to show the prev button if iPageNo > 1 then %> <FORM METHOD=POST ACTION="Search.asp?Page=<%=iPageNo-1%>" id=form1 name=form1> <INPUT TYPE=HIDDEN NAME=SearchText VALUE="<%=txtSearchTerms%>"> <INPUT TYPE=SUBMIT VALUE=" < Prev <%=RecsPerPage%> articles " TITLE="Click to see the next <%=RecsPerPage%> matches." id=SUBMIT1 name=SUBMIT1> </FORM> <% end if %> </TD><TD> <% 'We need to show next/prev if applicable if iMore > 0 then 'we have more records %> <FORM METHOD=POST ACTION="Search.asp?Page=<%=iPageNo+1%>" id=form1 name=form1> <INPUT TYPE=HIDDEN NAME=SearchText VALUE="<%=txtSearchTerms%>"> <INPUT TYPE=SUBMIT VALUE=" Next <%=RecsPerPage%> articles > " TITLE="Click to see the next <%=RecsPerPage%> matches." id=SUBMIT1 name=SUBMIT1> </FORM> <% end if %> </TD><TD ALIGN=RIGHT WIDTH=*><FONT SIZE=2><A HREF="/search/">Return to Search Page</A></FONT></TD></TR> </TABLE> <P> *** THIS #include simply contains HTML formatting... feel free to remove it *** <!--#include virtual="/bottom.shtml"--> <% objRS.Close Set objRS = Nothing objConn.Close set objConn = Nothing %>