|
FORMS ONLINE - Search By Keyword or Browse a Category
<%
If Request.QueryString("mode") <> "" Then
Dim SeachField
SeachField = Request.QueryString("mode")
' ADO Constants - Don't Change Them
'Const adOpenForwardOnly = 0
'Const adLockReadOnly = 1
'Const adCmdText = &H0001
'Const adUseClient = 3
Dim currentPage
If Len(Request.QueryString("currentPage")) = 0 Then
currentPage = 1
Else
currentPage = CInt(Request.QueryString("currentPage"))
End If
'Dim recordsToShow
' recordsToShow = 10
' Keyword/s to search
Dim strKeyword
strKeyword = split(Trim(Request.QueryString("look_for")), " ")
' Our Connection Object
'Dim con
Set con = CreateObject("ADODB.Connection")
con.Open strDB
' Our Recordset Object
'Dim rs
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = adUseClient
rs.PageSize = recordsToShow
rs.CacheSize = recordsToShow
' Searching the records for the DocumentTitle entered
if SeachField = "DocumentTitle" then
Select Case UBound(strKeyword)
Case 0 rs.Open "select * from DocumentMaster where DocumentFile like '%" & strKeyword(0) & "%' ", con, adOpenForwardOnly, adLockReadOnly, adCmdText
Case 1 rs.Open "select * from DocumentMaster where DocumentFile like '%" & strKeyword(0) & "%' and DocumentFile like '%" & strKeyword(1) & "%' ", con
Case 2 rs.Open "select * from DocumentMaster where DocumentFile like '%" & strKeyword(0) & "%' and DocumentFile like '%" & strKeyword(1) & "%' and DocumentFile like '%" & strKeyword(2) & "%' ", con
Case Else rs.Open "select * from DocumentMaster where DocumentFile like '%" & strKeyword(0) & "%' and DocumentFile like '%" & strKeyword(1) & "%' and DocumentFile like '%" & strKeyword(2) & "%' ", con
End Select
else
if SeachField = "DocumentCategory" Then
Select Case UBound(strKeyword)
Case 0 rs.Open "select * from DocumentMaster where DocumentCategory like '%" & strKeyword(0) & "%' ", con, adOpenForwardOnly, adLockReadOnly, adCmdText
Case 1 rs.Open "select * from DocumentMaster where DocumentCategory like '%" & strKeyword(0) & "%' and DocumentCategory like '%" & strKeyword(1) & "%' ", con
Case 2 rs.Open "select * from DocumentMaster where DocumentCategory like '%" & strKeyword(0) & "%' and DocumentCategory like '%" & strKeyword(1) & "%' and DocumentCategory like '%" & strKeyword(2) & "%' ", con
Case Else rs.Open "select * from DocumentMaster where DocumentCategory like '%" & strKeyword(0) & "%' and DocumentCategory like '%" & strKeyword(1) & "%' and DocumentCategory like '%" & strKeyword(2) & "%' ", con
End Select
end if
end If
' If the returning recordset is not empty
If Not rs.EOF Then
Dim totalpages
totalpages = rs.PageCount
rs.AbsolutePage = currentPage
' Showing total number of pages found and the current page number
Response.Write "Displaying Page " & currentPage & " of " & totalPages & " "
Response.Write "Total Records Found : " & rs.RecordCount & " "
Response.Write " Search Results for : " & Request.QueryString("look_for")
Response.Write "
"
If currentPage > 1 Then
Response.Write "Back"
Else
Response.Write "Back"
End If
Response.Write " "
If CInt(currentPage) <> CInt(totalPages) Then
Response.Write "Next"
Else
Response.Write "Next"
End If
response.write "
"
' Showing relevant records
Dim rcount, i, x , DocPos
For i = 1 To rs.PageSize
rcount = i
If currentPage > 1 Then
For x = 1 To (currentPage - 1)
rcount = 10 + rcount
Next
End If
If Not rs.EOF Then
response.write "| "
response.write "Document Link: " & rs("DocumentFile") & ""
response.write " | "
response.write "| "
response.write " Document Category:" & rs("DocumentCategory") & ""
response.write " | "
response.write "| "
response.write "Description: " & rs("DocumentDescription")
response.write " | "
response.write "| "
response.write " | "
rs.MoveNext
End If
Next
response.write " "
' Links to move through the records
If currentPage > 1 Then
Response.Write "Back"
Else
Response.Write "Back"
End If
Response.Write " "
If CInt(currentPage) <> CInt(totalPages) Then
Response.Write "Next"
Else
Response.Write "Next"
End If
Else
Response.Write "Sorry, no matching record was found." & vbcrlf
End If
' Done. Now release Objects
con.Close
Set con = Nothing
Set rs = Nothing
End If
%>
TIP - To save a form, right click on the link and
select "save as" from the dialog box. [more
help]
|